view_mapper 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +5 -0
- data/LICENSE +20 -0
- data/README +116 -0
- data/Rakefile +57 -0
- data/VERSION +1 -0
- data/generators/scaffold_for_view/USAGE +1 -0
- data/generators/scaffold_for_view/scaffold_for_view_generator.rb +37 -0
- data/generators/view_for/USAGE +1 -0
- data/generators/view_for/view_for_generator.rb +85 -0
- data/lib/view_mapper/auto_complete_templates/controller.rb +88 -0
- data/lib/view_mapper/auto_complete_templates/functional_test.rb +45 -0
- data/lib/view_mapper/auto_complete_templates/helper.rb +2 -0
- data/lib/view_mapper/auto_complete_templates/helper_test.rb +4 -0
- data/lib/view_mapper/auto_complete_templates/layout.html.erb +18 -0
- data/lib/view_mapper/auto_complete_templates/style.css +54 -0
- data/lib/view_mapper/auto_complete_templates/view_edit.html.erb +21 -0
- data/lib/view_mapper/auto_complete_templates/view_index.html.erb +24 -0
- data/lib/view_mapper/auto_complete_templates/view_new.html.erb +20 -0
- data/lib/view_mapper/auto_complete_templates/view_show.html.erb +10 -0
- data/lib/view_mapper/auto_complete_view.rb +44 -0
- data/lib/view_mapper/editable_manifest.rb +10 -0
- data/lib/view_mapper/route_action.rb +32 -0
- data/lib/view_mapper/view_mapper.rb +33 -0
- data/lib/view_mapper.rb +4 -0
- data/test/auto_complete_test.rb +146 -0
- data/test/database.yml +3 -0
- data/test/editable_manifest_test.rb +32 -0
- data/test/expected_templates/auto_complete/edit.html.erb +23 -0
- data/test/expected_templates/auto_complete/expected_routes.rb +45 -0
- data/test/expected_templates/auto_complete/index.html.erb +24 -0
- data/test/expected_templates/auto_complete/new.html.erb +22 -0
- data/test/expected_templates/auto_complete/show.html.erb +18 -0
- data/test/expected_templates/auto_complete/standard_routes.rb +43 -0
- data/test/expected_templates/auto_complete/testies.html.erb +18 -0
- data/test/expected_templates/auto_complete/testies_controller.rb +88 -0
- data/test/fake/fake_generator.rb +3 -0
- data/test/fake_view.rb +7 -0
- data/test/rails_generator/base.rb +266 -0
- data/test/rails_generator/commands.rb +621 -0
- data/test/rails_generator/generated_attribute.rb +46 -0
- data/test/rails_generator/generators/components/scaffold/scaffold_generator.rb +102 -0
- data/test/rails_generator/lookup.rb +249 -0
- data/test/rails_generator/manifest.rb +53 -0
- data/test/rails_generator/options.rb +150 -0
- data/test/rails_generator/scripts/destroy.rb +29 -0
- data/test/rails_generator/scripts/generate.rb +7 -0
- data/test/rails_generator/scripts/update.rb +12 -0
- data/test/rails_generator/scripts.rb +89 -0
- data/test/rails_generator/secret_key_generator.rb +24 -0
- data/test/rails_generator/simple_logger.rb +46 -0
- data/test/rails_generator/spec.rb +44 -0
- data/test/rails_generator.rb +43 -0
- data/test/scaffold_for_view_generator_test.rb +77 -0
- data/test/test_helper.rb +43 -0
- data/test/view_for_generator_test.rb +93 -0
- data/test/view_mapper_test.rb +29 -0
- data/view_mapper.gemspec +125 -0
- metadata +147 -0
@@ -0,0 +1,32 @@
|
|
1
|
+
module ViewMapper
|
2
|
+
module RouteAction
|
3
|
+
|
4
|
+
module Base
|
5
|
+
def route_code(route_options)
|
6
|
+
"map.#{route_options[:name]} '#{route_options[:path]}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'"
|
7
|
+
end
|
8
|
+
def route_file
|
9
|
+
'config/routes.rb'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
module Create
|
14
|
+
def route(route_options)
|
15
|
+
sentinel = 'ActionController::Routing::Routes.draw do |map|'
|
16
|
+
logger.route route_code(route_options)
|
17
|
+
gsub_file route_file, /(#{Regexp.escape(sentinel)})/mi do |m|
|
18
|
+
"#{m}\n #{route_code(route_options)}\n"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
module Destroy
|
24
|
+
def route(route_options)
|
25
|
+
logger.remove_route route_code(route_options)
|
26
|
+
to_remove = "\n #{route_code(route_options)}"
|
27
|
+
gsub_file route_file, /(#{to_remove})/mi, ''
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module ViewMapper
|
2
|
+
|
3
|
+
def initialize(runtime_args, runtime_options = {})
|
4
|
+
Rails::Generator::Commands::Base.class_eval { include RouteAction::Base }
|
5
|
+
Rails::Generator::Commands::Create.class_eval { include RouteAction::Create }
|
6
|
+
Rails::Generator::Commands::Destroy.class_eval { include RouteAction::Destroy }
|
7
|
+
super
|
8
|
+
if options[:view]
|
9
|
+
self.extend(view_class)
|
10
|
+
@source_root = source_root_for_view
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def view_class
|
15
|
+
"ViewMapper::#{view_name.camelize}View".constantize
|
16
|
+
end
|
17
|
+
|
18
|
+
def view_name
|
19
|
+
options[:view].split(':')[0]
|
20
|
+
end
|
21
|
+
|
22
|
+
def view_param
|
23
|
+
options[:view].split(':')[1]
|
24
|
+
end
|
25
|
+
|
26
|
+
def add_options!(opt)
|
27
|
+
opt.on("--view name", String, "Specify a view to generate") do |name|
|
28
|
+
options[:view] = name
|
29
|
+
end
|
30
|
+
super
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
data/lib/view_mapper.rb
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class AutoCompleteViewTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
attr_reader :singular_name
|
6
|
+
attr_reader :plural_name
|
7
|
+
attr_reader :attributes
|
8
|
+
attr_reader :auto_complete_attribute
|
9
|
+
attr_reader :controller_class_name
|
10
|
+
attr_reader :table_name
|
11
|
+
attr_reader :class_name
|
12
|
+
attr_reader :file_name
|
13
|
+
attr_reader :controller_singular_name
|
14
|
+
|
15
|
+
def generator_cmd_line(gen, args)
|
16
|
+
if gen == 'view_for'
|
17
|
+
cmd_line = ['testy']
|
18
|
+
else
|
19
|
+
cmd_line = ['testy', 'first_name:string', 'last_name:string', 'address:string']
|
20
|
+
end
|
21
|
+
(cmd_line << args).flatten
|
22
|
+
end
|
23
|
+
|
24
|
+
def generator_script_cmd_line(gen, args)
|
25
|
+
([gen] << generator_cmd_line(gen, args)).flatten
|
26
|
+
end
|
27
|
+
|
28
|
+
def new_generator_for_test_model(gen, args)
|
29
|
+
Rails::Generator::Base.instance(gen, generator_cmd_line(gen, args))
|
30
|
+
end
|
31
|
+
|
32
|
+
generators = %w{ view_for scaffold_for_view }
|
33
|
+
generators.each do |gen|
|
34
|
+
|
35
|
+
context "A #{gen} generator instantiated for a test model" do
|
36
|
+
should "return an error message without an auto_complete param" do
|
37
|
+
Rails::Generator::Base.logger.expects('error').with('No auto_complete attribute specified.')
|
38
|
+
new_generator_for_test_model(gen, ['--view', 'auto_complete'])
|
39
|
+
end
|
40
|
+
|
41
|
+
should "return an error message with a bad auto_complete param" do
|
42
|
+
Rails::Generator::Base.logger.expects('error').with('Field \'blah\' does not exist.')
|
43
|
+
new_generator_for_test_model(gen, ['--view', 'auto_complete:blah'])
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "A #{gen} generator instantiated for a test model with auto_complete on the first_name field" do
|
48
|
+
setup do
|
49
|
+
@gen = new_generator_for_test_model(gen, ['--view', 'auto_complete:first_name'])
|
50
|
+
end
|
51
|
+
|
52
|
+
should "find the auto complete column name" do
|
53
|
+
assert_equal 'first_name', @gen.auto_complete_attribute
|
54
|
+
end
|
55
|
+
|
56
|
+
should "have the correct auto_complete_for method name" do
|
57
|
+
assert_equal 'auto_complete_for_testy_first_name', @gen.auto_complete_for_method
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context "A #{gen} generator instantiated for a test model with auto_complete on the address field" do
|
62
|
+
setup do
|
63
|
+
@gen = new_generator_for_test_model(gen, ['--view', 'auto_complete:address'])
|
64
|
+
end
|
65
|
+
|
66
|
+
should "return the proper source root folder" do
|
67
|
+
assert_equal './test/../lib/view_mapper/auto_complete_templates', @gen.source_root
|
68
|
+
end
|
69
|
+
|
70
|
+
view_for_templates = %w{ new edit index show }
|
71
|
+
view_for_templates.each do | template |
|
72
|
+
should "render the #{template} template as expected" do
|
73
|
+
@attributes = @gen.attributes
|
74
|
+
@singular_name = @gen.singular_name
|
75
|
+
@plural_name = @gen.plural_name
|
76
|
+
@auto_complete_attribute = @gen.auto_complete_attribute
|
77
|
+
template_file = File.open(File.join(File.dirname(__FILE__), "/../lib/view_mapper/auto_complete_templates/view_#{template}.html.erb"))
|
78
|
+
result = ERB.new(template_file.read, nil, '-').result(binding)
|
79
|
+
expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/auto_complete/#{template}.html.erb"))
|
80
|
+
assert_equal expected_file.read, result
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
should "render the layout template as expected" do
|
85
|
+
@controller_class_name = @gen.controller_class_name
|
86
|
+
template_file = File.open(File.join(File.dirname(__FILE__), "/../lib/view_mapper/auto_complete_templates/layout.html.erb"))
|
87
|
+
result = ERB.new(template_file.read, nil, '-').result(binding)
|
88
|
+
expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/auto_complete/testies.html.erb"))
|
89
|
+
assert_equal expected_file.read, result
|
90
|
+
end
|
91
|
+
|
92
|
+
should "render the controller template as expected" do
|
93
|
+
@controller_class_name = @gen.controller_class_name
|
94
|
+
@table_name = @gen.table_name
|
95
|
+
@class_name = @gen.class_name
|
96
|
+
@file_name = @gen.file_name
|
97
|
+
@controller_singular_name = @gen.controller_singular_name
|
98
|
+
@auto_complete_attribute = @gen.auto_complete_attribute
|
99
|
+
template_file = File.open(File.join(File.dirname(__FILE__), "/../lib/view_mapper/auto_complete_templates/controller.rb"))
|
100
|
+
result = ERB.new(template_file.read, nil, '-').result(binding)
|
101
|
+
expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/auto_complete/testies_controller.rb"))
|
102
|
+
assert_equal expected_file.read, result
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
context "A Rails generator script" do
|
107
|
+
setup do
|
108
|
+
setup_test_model
|
109
|
+
@generator_script = Rails::Generator::Scripts::Generate.new
|
110
|
+
end
|
111
|
+
|
112
|
+
should "add the proper auto_complete route to routes.rb when run on the #{gen} generator with a valid auto_complete field" do
|
113
|
+
Rails::Generator::Commands::Create.any_instance.stubs(:directory)
|
114
|
+
Rails::Generator::Commands::Create.any_instance.stubs(:template)
|
115
|
+
Rails::Generator::Commands::Create.any_instance.stubs(:route_resources)
|
116
|
+
Rails::Generator::Commands::Create.any_instance.stubs(:file)
|
117
|
+
Rails::Generator::Commands::Create.any_instance.stubs(:dependency)
|
118
|
+
Rails::Generator::Base.logger.stubs(:route)
|
119
|
+
|
120
|
+
expected_path = File.dirname(__FILE__) + '/expected_templates/auto_complete'
|
121
|
+
standard_routes_file = expected_path + '/standard_routes.rb'
|
122
|
+
expected_routes_file = expected_path + '/expected_routes.rb'
|
123
|
+
test_routes_file = expected_path + '/routes.rb'
|
124
|
+
ViewForGenerator.any_instance.stubs(:destination_path).returns test_routes_file
|
125
|
+
ScaffoldForViewGenerator.any_instance.stubs(:destination_path).returns test_routes_file
|
126
|
+
File.copy(standard_routes_file, test_routes_file)
|
127
|
+
Rails::Generator::Commands::Create.any_instance.stubs(:route_file).returns(test_routes_file)
|
128
|
+
@generator_script.run(generator_script_cmd_line(gen, ['--view', 'auto_complete:address']))
|
129
|
+
assert_equal File.open(expected_routes_file).read, File.open(test_routes_file).read
|
130
|
+
File.delete(test_routes_file)
|
131
|
+
end
|
132
|
+
|
133
|
+
should "not perform any actions when run on the #{gen} generator with no auto_complete field" do
|
134
|
+
Rails::Generator::Commands::Create.any_instance.expects(:directory).never
|
135
|
+
Rails::Generator::Commands::Create.any_instance.expects(:template).never
|
136
|
+
Rails::Generator::Commands::Create.any_instance.expects(:route_resources).never
|
137
|
+
Rails::Generator::Commands::Create.any_instance.expects(:file).never
|
138
|
+
Rails::Generator::Commands::Create.any_instance.expects(:route).never
|
139
|
+
Rails::Generator::Base.logger.stubs(:error)
|
140
|
+
Rails::Generator::Base.logger.stubs(:route)
|
141
|
+
@generator_script.run(generator_script_cmd_line(gen, ['--view', 'auto_complete']))
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
data/test/database.yml
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class EditableManifestTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def record
|
6
|
+
EditableManifest.new(self) { |m| yield m }
|
7
|
+
end
|
8
|
+
|
9
|
+
def action(param)
|
10
|
+
@actions_received << param
|
11
|
+
end
|
12
|
+
|
13
|
+
context "An editable manifest with a couple of recorded actions" do
|
14
|
+
setup do
|
15
|
+
@actions_received = []
|
16
|
+
@man = record do |m|
|
17
|
+
m.action('one')
|
18
|
+
m.action('two')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
should "allow me to delete an action" do
|
23
|
+
@man.edit do |action|
|
24
|
+
action unless action[1].include? 'one'
|
25
|
+
end
|
26
|
+
@man.replay(self)
|
27
|
+
assert_does_not_contain @actions_received, 'one'
|
28
|
+
assert_contains @actions_received, 'two'
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<h1>Editing testy</h1>
|
2
|
+
|
3
|
+
<% form_for(@testy) do |f| %>
|
4
|
+
<%= f.error_messages %>
|
5
|
+
<p>
|
6
|
+
<%= f.label :first_name %><br />
|
7
|
+
<%= f.text_field :first_name %>
|
8
|
+
</p>
|
9
|
+
<p>
|
10
|
+
<%= f.label :last_name %><br />
|
11
|
+
<%= f.text_field :last_name %>
|
12
|
+
</p>
|
13
|
+
<p>
|
14
|
+
<%= f.label :address %><br />
|
15
|
+
<%= text_field_with_auto_complete :testy, :address, {}, { :method => :get } %>
|
16
|
+
</p>
|
17
|
+
<p>
|
18
|
+
<%= f.submit 'Update' %>
|
19
|
+
</p>
|
20
|
+
<% end %>
|
21
|
+
|
22
|
+
<%= link_to 'Show', @testy %> |
|
23
|
+
<%= link_to 'Back', testies_path %>
|
@@ -0,0 +1,45 @@
|
|
1
|
+
ActionController::Routing::Routes.draw do |map|
|
2
|
+
map.connect 'auto_complete_for_testy_address', :controller => 'testies', :action => 'auto_complete_for_testy_address'
|
3
|
+
|
4
|
+
# The priority is based upon order of creation: first created -> highest priority.
|
5
|
+
|
6
|
+
# Sample of regular route:
|
7
|
+
# map.connect 'products/:id', :controller => 'catalog', :action => 'view'
|
8
|
+
# Keep in mind you can assign values other than :controller and :action
|
9
|
+
|
10
|
+
# Sample of named route:
|
11
|
+
# map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase'
|
12
|
+
# This route can be invoked with purchase_url(:id => product.id)
|
13
|
+
|
14
|
+
# Sample resource route (maps HTTP verbs to controller actions automatically):
|
15
|
+
# map.resources :products
|
16
|
+
|
17
|
+
# Sample resource route with options:
|
18
|
+
# map.resources :products, :member => { :short => :get, :toggle => :post }, :collection => { :sold => :get }
|
19
|
+
|
20
|
+
# Sample resource route with sub-resources:
|
21
|
+
# map.resources :products, :has_many => [ :comments, :sales ], :has_one => :seller
|
22
|
+
|
23
|
+
# Sample resource route with more complex sub-resources
|
24
|
+
# map.resources :products do |products|
|
25
|
+
# products.resources :comments
|
26
|
+
# products.resources :sales, :collection => { :recent => :get }
|
27
|
+
# end
|
28
|
+
|
29
|
+
# Sample resource route within a namespace:
|
30
|
+
# map.namespace :admin do |admin|
|
31
|
+
# # Directs /admin/products/* to Admin::ProductsController (app/controllers/admin/products_controller.rb)
|
32
|
+
# admin.resources :products
|
33
|
+
# end
|
34
|
+
|
35
|
+
# You can have the root of your site routed with map.root -- just remember to delete public/index.html.
|
36
|
+
# map.root :controller => "welcome"
|
37
|
+
|
38
|
+
# See how all your routes lay out with "rake routes"
|
39
|
+
|
40
|
+
# Install the default routes as the lowest priority.
|
41
|
+
# Note: These default routes make all actions in every controller accessible via GET requests. You should
|
42
|
+
# consider removing the them or commenting them out if you're using named routes and resources.
|
43
|
+
map.connect ':controller/:action/:id'
|
44
|
+
map.connect ':controller/:action/:id.:format'
|
45
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
<h1>Listing testies</h1>
|
2
|
+
|
3
|
+
<table>
|
4
|
+
<tr>
|
5
|
+
<th>First name</th>
|
6
|
+
<th>Last name</th>
|
7
|
+
<th>Address</th>
|
8
|
+
</tr>
|
9
|
+
|
10
|
+
<% @testies.each do |testy| %>
|
11
|
+
<tr>
|
12
|
+
<td><%=h testy.first_name %></td>
|
13
|
+
<td><%=h testy.last_name %></td>
|
14
|
+
<td><%=h testy.address %></td>
|
15
|
+
<td><%= link_to 'Show', testy %></td>
|
16
|
+
<td><%= link_to 'Edit', edit_testy_path(testy) %></td>
|
17
|
+
<td><%= link_to 'Destroy', testy, :confirm => 'Are you sure?', :method => :delete %></td>
|
18
|
+
</tr>
|
19
|
+
<% end %>
|
20
|
+
</table>
|
21
|
+
|
22
|
+
<br />
|
23
|
+
|
24
|
+
<%= link_to 'New testy', new_testy_path %>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
<h1>New testy</h1>
|
2
|
+
|
3
|
+
<% form_for(@testy) do |f| %>
|
4
|
+
<%= f.error_messages %>
|
5
|
+
<p>
|
6
|
+
<%= f.label :first_name %><br />
|
7
|
+
<%= f.text_field :first_name %>
|
8
|
+
</p>
|
9
|
+
<p>
|
10
|
+
<%= f.label :last_name %><br />
|
11
|
+
<%= f.text_field :last_name %>
|
12
|
+
</p>
|
13
|
+
<p>
|
14
|
+
<%= f.label :address %><br />
|
15
|
+
<%= text_field_with_auto_complete :testy, :address, {}, { :method => :get } %>
|
16
|
+
</p>
|
17
|
+
<p>
|
18
|
+
<%= f.submit 'Create' %>
|
19
|
+
</p>
|
20
|
+
<% end %>
|
21
|
+
|
22
|
+
<%= link_to 'Back', testies_path %>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<p>
|
2
|
+
<b>First name:</b>
|
3
|
+
<%=h @testy.first_name %>
|
4
|
+
</p>
|
5
|
+
|
6
|
+
<p>
|
7
|
+
<b>Last name:</b>
|
8
|
+
<%=h @testy.last_name %>
|
9
|
+
</p>
|
10
|
+
|
11
|
+
<p>
|
12
|
+
<b>Address:</b>
|
13
|
+
<%=h @testy.address %>
|
14
|
+
</p>
|
15
|
+
|
16
|
+
|
17
|
+
<%= link_to 'Edit', edit_testy_path(@testy) %> |
|
18
|
+
<%= link_to 'Back', testies_path %>
|
@@ -0,0 +1,43 @@
|
|
1
|
+
ActionController::Routing::Routes.draw do |map|
|
2
|
+
# The priority is based upon order of creation: first created -> highest priority.
|
3
|
+
|
4
|
+
# Sample of regular route:
|
5
|
+
# map.connect 'products/:id', :controller => 'catalog', :action => 'view'
|
6
|
+
# Keep in mind you can assign values other than :controller and :action
|
7
|
+
|
8
|
+
# Sample of named route:
|
9
|
+
# map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase'
|
10
|
+
# This route can be invoked with purchase_url(:id => product.id)
|
11
|
+
|
12
|
+
# Sample resource route (maps HTTP verbs to controller actions automatically):
|
13
|
+
# map.resources :products
|
14
|
+
|
15
|
+
# Sample resource route with options:
|
16
|
+
# map.resources :products, :member => { :short => :get, :toggle => :post }, :collection => { :sold => :get }
|
17
|
+
|
18
|
+
# Sample resource route with sub-resources:
|
19
|
+
# map.resources :products, :has_many => [ :comments, :sales ], :has_one => :seller
|
20
|
+
|
21
|
+
# Sample resource route with more complex sub-resources
|
22
|
+
# map.resources :products do |products|
|
23
|
+
# products.resources :comments
|
24
|
+
# products.resources :sales, :collection => { :recent => :get }
|
25
|
+
# end
|
26
|
+
|
27
|
+
# Sample resource route within a namespace:
|
28
|
+
# map.namespace :admin do |admin|
|
29
|
+
# # Directs /admin/products/* to Admin::ProductsController (app/controllers/admin/products_controller.rb)
|
30
|
+
# admin.resources :products
|
31
|
+
# end
|
32
|
+
|
33
|
+
# You can have the root of your site routed with map.root -- just remember to delete public/index.html.
|
34
|
+
# map.root :controller => "welcome"
|
35
|
+
|
36
|
+
# See how all your routes lay out with "rake routes"
|
37
|
+
|
38
|
+
# Install the default routes as the lowest priority.
|
39
|
+
# Note: These default routes make all actions in every controller accessible via GET requests. You should
|
40
|
+
# consider removing the them or commenting them out if you're using named routes and resources.
|
41
|
+
map.connect ':controller/:action/:id'
|
42
|
+
map.connect ':controller/:action/:id.:format'
|
43
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
5
|
+
<head>
|
6
|
+
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
|
7
|
+
<title>Testies: <%= controller.action_name %></title>
|
8
|
+
<%= stylesheet_link_tag 'scaffold' %>
|
9
|
+
<%= javascript_include_tag :defaults %>
|
10
|
+
</head>
|
11
|
+
<body>
|
12
|
+
|
13
|
+
<p style="color: green"><%= flash[:notice] %></p>
|
14
|
+
|
15
|
+
<%= yield %>
|
16
|
+
|
17
|
+
</body>
|
18
|
+
</html>
|
@@ -0,0 +1,88 @@
|
|
1
|
+
class TestiesController < ApplicationController
|
2
|
+
|
3
|
+
auto_complete_for :testy, :address
|
4
|
+
|
5
|
+
# GET /testies
|
6
|
+
# GET /testies.xml
|
7
|
+
def index
|
8
|
+
@testies = Testy.all
|
9
|
+
|
10
|
+
respond_to do |format|
|
11
|
+
format.html # index.html.erb
|
12
|
+
format.xml { render :xml => @testies }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# GET /testies/1
|
17
|
+
# GET /testies/1.xml
|
18
|
+
def show
|
19
|
+
@testy = Testy.find(params[:id])
|
20
|
+
|
21
|
+
respond_to do |format|
|
22
|
+
format.html # show.html.erb
|
23
|
+
format.xml { render :xml => @testy }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# GET /testies/new
|
28
|
+
# GET /testies/new.xml
|
29
|
+
def new
|
30
|
+
@testy = Testy.new
|
31
|
+
|
32
|
+
respond_to do |format|
|
33
|
+
format.html # new.html.erb
|
34
|
+
format.xml { render :xml => @testy }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# GET /testies/1/edit
|
39
|
+
def edit
|
40
|
+
@testy = Testy.find(params[:id])
|
41
|
+
end
|
42
|
+
|
43
|
+
# POST /testies
|
44
|
+
# POST /testies.xml
|
45
|
+
def create
|
46
|
+
@testy = Testy.new(params[:testy])
|
47
|
+
|
48
|
+
respond_to do |format|
|
49
|
+
if @testy.save
|
50
|
+
flash[:notice] = 'Testy was successfully created.'
|
51
|
+
format.html { redirect_to(@testy) }
|
52
|
+
format.xml { render :xml => @testy, :status => :created, :location => @testy }
|
53
|
+
else
|
54
|
+
format.html { render :action => "new" }
|
55
|
+
format.xml { render :xml => @testy.errors, :status => :unprocessable_entity }
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# PUT /testies/1
|
61
|
+
# PUT /testies/1.xml
|
62
|
+
def update
|
63
|
+
@testy = Testy.find(params[:id])
|
64
|
+
|
65
|
+
respond_to do |format|
|
66
|
+
if @testy.update_attributes(params[:testy])
|
67
|
+
flash[:notice] = 'Testy was successfully updated.'
|
68
|
+
format.html { redirect_to(@testy) }
|
69
|
+
format.xml { head :ok }
|
70
|
+
else
|
71
|
+
format.html { render :action => "edit" }
|
72
|
+
format.xml { render :xml => @testy.errors, :status => :unprocessable_entity }
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
# DELETE /testies/1
|
78
|
+
# DELETE /testies/1.xml
|
79
|
+
def destroy
|
80
|
+
@testy = Testy.find(params[:id])
|
81
|
+
@testy.destroy
|
82
|
+
|
83
|
+
respond_to do |format|
|
84
|
+
format.html { redirect_to(testies_url) }
|
85
|
+
format.xml { head :ok }
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|