view_mapper 0.3.3 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +3 -1
- data/VERSION +1 -1
- data/lib/view_mapper.rb +1 -0
- data/lib/view_mapper/belongs_to_parent_models.rb +12 -26
- data/lib/view_mapper/has_many_child_models.rb +9 -9
- data/lib/view_mapper/model_info.rb +56 -18
- data/lib/view_mapper/views/belongs_to/belongs_to_view.rb +14 -0
- data/lib/view_mapper/views/belongs_to_auto_complete/belongs_to_auto_complete_view.rb +9 -2
- data/lib/view_mapper/views/has_many/templates/helper.rb +1 -1
- data/lib/view_mapper/views/has_many/templates/view_child_form.html.erb +1 -1
- data/lib/view_mapper/views/has_many/templates/view_form.html.erb +1 -1
- data/lib/view_mapper/views/has_many_existing/has_many_existing_view.rb +126 -0
- data/lib/view_mapper/views/has_many_existing/templates/model.rb +21 -0
- data/lib/view_mapper/views/has_many_existing/templates/view_child_form.html.erb +16 -0
- data/lib/view_mapper/views/has_many_existing/templates/view_form.html.erb +20 -0
- data/lib/view_mapper/views/has_many_existing/templates/view_show.html.erb +26 -0
- data/test/generators/scaffold_for_view/scaffold_for_view_generator_test.rb +15 -15
- data/test/generators/view_for/view_for_generator_test.rb +18 -18
- data/test/model_info_test.rb +91 -20
- data/test/test_helper.rb +75 -105
- data/test/views/auto_complete/auto_complete_test.rb +104 -102
- data/test/views/auto_complete/expected_templates/edit.html.erb +6 -6
- data/test/views/auto_complete/expected_templates/expected_routes.rb +1 -1
- data/test/views/auto_complete/expected_templates/index.html.erb +10 -10
- data/test/views/auto_complete/expected_templates/new.html.erb +5 -5
- data/test/views/auto_complete/expected_templates/show.html.erb +6 -6
- data/test/views/auto_complete/expected_templates/{testies.html.erb → test_models.html.erb} +1 -1
- data/test/views/auto_complete/expected_templates/test_models_controller.rb +89 -0
- data/test/views/belongs_to/belongs_to_test.rb +238 -202
- data/test/views/belongs_to/expected_templates/_form.html.erb +4 -4
- data/test/views/belongs_to/expected_templates/child_model.rb +10 -0
- data/test/views/belongs_to/expected_templates/create_child_models.rb +18 -0
- data/test/views/belongs_to/expected_templates/edit.html.erb +4 -4
- data/test/views/belongs_to/expected_templates/index.html.erb +11 -11
- data/test/views/belongs_to/expected_templates/new.html.erb +3 -3
- data/test/views/belongs_to/expected_templates/show.html.erb +7 -7
- data/test/views/belongs_to_auto_complete/belongs_to_auto_complete_test.rb +440 -406
- data/test/views/belongs_to_auto_complete/expected_templates/_form.html.erb +4 -4
- data/test/views/belongs_to_auto_complete/expected_templates/child_model.rb +16 -0
- data/test/views/belongs_to_auto_complete/expected_templates/{some_other_models.html.erb → child_models.html.erb} +1 -1
- data/test/views/belongs_to_auto_complete/expected_templates/child_models_controller.rb +89 -0
- data/test/views/belongs_to_auto_complete/expected_templates/create_child_models.rb +18 -0
- data/test/views/belongs_to_auto_complete/expected_templates/edit.html.erb +4 -4
- data/test/views/belongs_to_auto_complete/expected_templates/expected_routes.rb +2 -2
- data/test/views/belongs_to_auto_complete/expected_templates/index.html.erb +11 -11
- data/test/views/belongs_to_auto_complete/expected_templates/new.html.erb +3 -3
- data/test/views/belongs_to_auto_complete/expected_templates/show.html.erb +7 -7
- data/test/views/has_many/expected_templates/_form.html.erb +8 -8
- data/test/views/has_many/expected_templates/{_person.html.erb → _second_child_model.html.erb} +5 -5
- data/test/views/has_many/expected_templates/create_parent_models.rb +16 -0
- data/test/views/has_many/expected_templates/edit.html.erb +4 -4
- data/test/views/has_many/expected_templates/index.html.erb +7 -7
- data/test/views/has_many/expected_templates/new.html.erb +3 -3
- data/test/views/has_many/expected_templates/{parent.rb → parent_model.rb} +5 -5
- data/test/views/has_many/expected_templates/show.html.erb +15 -15
- data/test/views/has_many/has_many_view_test.rb +334 -292
- data/test/views/has_many_existing/expected_templates/_assignment.html.erb +14 -0
- data/test/views/has_many_existing/expected_templates/_form.html.erb +16 -0
- data/test/views/{has_many/expected_templates/create_parents.rb → has_many_existing/expected_templates/create_programmers.rb} +3 -3
- data/test/views/has_many_existing/expected_templates/edit.html.erb +11 -0
- data/test/views/has_many_existing/expected_templates/index.html.erb +20 -0
- data/test/views/has_many_existing/expected_templates/new.html.erb +10 -0
- data/test/views/has_many_existing/expected_templates/programmer.rb +10 -0
- data/test/views/has_many_existing/expected_templates/show.html.erb +20 -0
- data/test/views/has_many_existing/has_many_existing_test.rb +495 -0
- data/test/views/paperclip/expected_templates/{create_testies.rb → create_test_models.rb} +3 -3
- data/test/views/paperclip/expected_templates/edit.html.erb +4 -4
- data/test/views/paperclip/expected_templates/index.html.erb +10 -10
- data/test/views/paperclip/expected_templates/new.html.erb +3 -3
- data/test/views/paperclip/expected_templates/show.html.erb +8 -8
- data/test/views/paperclip/expected_templates/{testy.rb → test_model.rb} +1 -1
- data/test/views/paperclip/paperclip_view_test.rb +254 -226
- data/view_mapper.gemspec +43 -27
- metadata +64 -37
- data/test/views/auto_complete/expected_templates/actual_index +0 -26
- data/test/views/auto_complete/expected_templates/testies_controller.rb +0 -89
- data/test/views/belongs_to/expected_templates/create_some_other_models.rb +0 -18
- data/test/views/belongs_to/expected_templates/some_other_model.rb +0 -10
- data/test/views/belongs_to_auto_complete/expected_templates/create_some_other_models.rb +0 -18
- data/test/views/belongs_to_auto_complete/expected_templates/some_other_model.rb +0 -16
- data/test/views/belongs_to_auto_complete/expected_templates/some_other_models_controller.rb +0 -89
@@ -12,141 +12,143 @@ class AutoCompleteViewTest < Test::Unit::TestCase
|
|
12
12
|
attr_reader :file_name
|
13
13
|
attr_reader :controller_singular_name
|
14
14
|
|
15
|
-
context "A
|
15
|
+
context "A rails app that has the auto_complete plugin installed" do
|
16
16
|
setup do
|
17
|
-
|
17
|
+
ActionController::Base.send(:include, MockAutoComplete)
|
18
18
|
end
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
assert_contains gen.auto_complete_attributes, 'address'
|
25
|
-
assert_does_not_contain gen.auto_complete_attributes, 'some_flag'
|
26
|
-
end
|
27
|
-
end
|
20
|
+
context "A view_for generator instantiated for a test model" do
|
21
|
+
setup do
|
22
|
+
ClassFactory :test_model
|
23
|
+
end
|
28
24
|
|
29
|
-
|
30
|
-
|
31
|
-
|
25
|
+
should "detect all of the text fields when no auto_complete field is specified" do
|
26
|
+
gen = new_generator_for_test_model('view_for', ['--view', 'auto_complete'])
|
27
|
+
assert_contains gen.auto_complete_attributes, 'first_name'
|
28
|
+
assert_contains gen.auto_complete_attributes, 'last_name'
|
29
|
+
assert_contains gen.auto_complete_attributes, 'address'
|
30
|
+
assert_does_not_contain gen.auto_complete_attributes, 'some_flag'
|
31
|
+
end
|
32
32
|
end
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
34
|
+
context "A scaffold_for_view generator instantiated for a test model" do
|
35
|
+
|
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('scaffold_for_view', ['--view', 'auto_complete'])
|
39
|
+
end
|
37
40
|
end
|
38
|
-
end
|
39
41
|
|
40
|
-
|
41
|
-
|
42
|
+
generators = %w{ view_for scaffold_for_view }
|
43
|
+
generators.each do |gen|
|
42
44
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
45
|
+
context "A #{gen} generator instantiated for a test model" do
|
46
|
+
setup do
|
47
|
+
ClassFactory :test_model
|
48
|
+
end
|
47
49
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
50
|
+
should "return an error message with a bad auto_complete param" do
|
51
|
+
Rails::Generator::Base.logger.expects('error').with('Field \'blah\' does not exist.')
|
52
|
+
new_generator_for_test_model(gen, ['--view', 'auto_complete:blah'])
|
53
|
+
end
|
52
54
|
|
53
|
-
|
54
|
-
|
55
|
-
|
55
|
+
should "return an error message when the auto_complete param matches a field that is not a text field" do
|
56
|
+
Rails::Generator::Base.logger.expects('error').with('Field \'some_flag\' is not a text field.')
|
57
|
+
new_generator_for_test_model(gen, ['--view', 'auto_complete:some_flag'])
|
58
|
+
end
|
56
59
|
end
|
57
|
-
end
|
58
60
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
61
|
+
context "A #{gen} generator instantiated for a test model with auto_complete on the first and last name fields" do
|
62
|
+
setup do
|
63
|
+
ClassFactory :test_model
|
64
|
+
@gen = new_generator_for_test_model(gen, ['--view', 'auto_complete:first_name,last_name'])
|
65
|
+
end
|
64
66
|
|
65
|
-
|
66
|
-
|
67
|
-
|
67
|
+
should "return the proper source root" do
|
68
|
+
assert_equal File.expand_path(File.dirname(__FILE__) + '/../../..//lib/view_mapper/views/auto_complete/templates'), ViewMapper::AutoCompleteView.source_root
|
69
|
+
end
|
68
70
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
71
|
+
view_for_templates = %w{ new edit index show }
|
72
|
+
view_for_templates.each do | template |
|
73
|
+
should "render the #{template} template as expected" do
|
74
|
+
@attributes = @gen.attributes
|
75
|
+
@singular_name = @gen.singular_name
|
76
|
+
@plural_name = @gen.plural_name
|
77
|
+
@auto_complete_attributes = @gen.auto_complete_attributes
|
78
|
+
template_file = File.open(@gen.source_path("view_#{template}.html.erb"))
|
79
|
+
result = ERB.new(template_file.read, nil, '-').result(binding)
|
80
|
+
expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/#{template}.html.erb"), 'rb')
|
81
|
+
assert_equal expected_file.read, result
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
should "render the layout template as expected" do
|
86
|
+
@controller_class_name = @gen.controller_class_name
|
87
|
+
template_file = File.open(@gen.source_path("layout.html.erb"))
|
88
|
+
result = ERB.new(template_file.read, nil, '-').result(binding)
|
89
|
+
expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/test_models.html.erb"))
|
90
|
+
assert_equal expected_file.read, result
|
91
|
+
end
|
92
|
+
|
93
|
+
should "render the controller template as expected" do
|
94
|
+
@controller_class_name = @gen.controller_class_name
|
95
|
+
@table_name = @gen.table_name
|
96
|
+
@class_name = @gen.class_name
|
97
|
+
@file_name = @gen.file_name
|
98
|
+
@controller_singular_name = @gen.controller_singular_name
|
75
99
|
@auto_complete_attributes = @gen.auto_complete_attributes
|
76
|
-
template_file = File.open(@gen.source_path("
|
100
|
+
template_file = File.open(@gen.source_path("controller.rb"))
|
77
101
|
result = ERB.new(template_file.read, nil, '-').result(binding)
|
78
|
-
expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates
|
102
|
+
expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/test_models_controller.rb"))
|
79
103
|
assert_equal expected_file.read, result
|
80
104
|
end
|
81
105
|
end
|
82
106
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
assert_equal expected_file.read, result
|
89
|
-
end
|
107
|
+
context "A Rails generator script" do
|
108
|
+
setup do
|
109
|
+
ClassFactory :test_model
|
110
|
+
@generator_script = Rails::Generator::Scripts::Generate.new
|
111
|
+
end
|
90
112
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
113
|
+
should "add the proper auto_complete route to routes.rb when run on the #{gen} generator with a valid auto_complete field" do
|
114
|
+
Rails::Generator::Commands::Create.any_instance.stubs(:directory)
|
115
|
+
Rails::Generator::Commands::Create.any_instance.stubs(:template)
|
116
|
+
Rails::Generator::Commands::Create.any_instance.stubs(:route_resources)
|
117
|
+
Rails::Generator::Commands::Create.any_instance.stubs(:file)
|
118
|
+
Rails::Generator::Commands::Create.any_instance.stubs(:dependency)
|
119
|
+
Rails::Generator::Base.logger.stubs(:route)
|
120
|
+
|
121
|
+
expected_path = File.dirname(__FILE__) + '/expected_templates'
|
122
|
+
standard_routes_file = expected_path + '/standard_routes.rb'
|
123
|
+
expected_routes_file = expected_path + '/expected_routes.rb'
|
124
|
+
test_routes_file = expected_path + '/routes.rb'
|
125
|
+
ViewForGenerator.any_instance.stubs(:destination_path).returns test_routes_file
|
126
|
+
ScaffoldForViewGenerator.any_instance.stubs(:destination_path).returns test_routes_file
|
127
|
+
FileUtils.copy(standard_routes_file, test_routes_file)
|
128
|
+
Rails::Generator::Commands::Create.any_instance.stubs(:route_file).returns(test_routes_file)
|
129
|
+
@generator_script.run(generator_script_cmd_line(gen, ['--view', 'auto_complete:address']))
|
130
|
+
assert_equal File.open(expected_routes_file).read, File.open(test_routes_file).read
|
131
|
+
File.delete(test_routes_file)
|
132
|
+
end
|
102
133
|
end
|
103
134
|
end
|
104
135
|
|
105
136
|
context "A Rails generator script" do
|
106
137
|
setup do
|
107
|
-
setup_test_model
|
108
138
|
@generator_script = Rails::Generator::Scripts::Generate.new
|
109
139
|
end
|
110
140
|
|
111
|
-
should "
|
112
|
-
Rails::Generator::Commands::Create.any_instance.
|
113
|
-
Rails::Generator::Commands::Create.any_instance.
|
114
|
-
Rails::Generator::Commands::Create.any_instance.
|
115
|
-
Rails::Generator::Commands::Create.any_instance.
|
116
|
-
Rails::Generator::Commands::Create.any_instance.
|
141
|
+
should "not perform any actions when run on the scaffold_for_view generator with no auto_complete field" do
|
142
|
+
Rails::Generator::Commands::Create.any_instance.expects(:directory).never
|
143
|
+
Rails::Generator::Commands::Create.any_instance.expects(:template).never
|
144
|
+
Rails::Generator::Commands::Create.any_instance.expects(:route_resources).never
|
145
|
+
Rails::Generator::Commands::Create.any_instance.expects(:file).never
|
146
|
+
Rails::Generator::Commands::Create.any_instance.expects(:route).never
|
147
|
+
Rails::Generator::Base.logger.stubs(:error)
|
117
148
|
Rails::Generator::Base.logger.stubs(:route)
|
118
|
-
|
119
|
-
expected_path = File.dirname(__FILE__) + '/expected_templates'
|
120
|
-
standard_routes_file = expected_path + '/standard_routes.rb'
|
121
|
-
expected_routes_file = expected_path + '/expected_routes.rb'
|
122
|
-
test_routes_file = expected_path + '/routes.rb'
|
123
|
-
ViewForGenerator.any_instance.stubs(:destination_path).returns test_routes_file
|
124
|
-
ScaffoldForViewGenerator.any_instance.stubs(:destination_path).returns test_routes_file
|
125
|
-
FileUtils.copy(standard_routes_file, test_routes_file)
|
126
|
-
Rails::Generator::Commands::Create.any_instance.stubs(:route_file).returns(test_routes_file)
|
127
|
-
@generator_script.run(generator_script_cmd_line(gen, ['--view', 'auto_complete:address']))
|
128
|
-
assert_equal File.open(expected_routes_file).read, File.open(test_routes_file).read
|
129
|
-
File.delete(test_routes_file)
|
149
|
+
@generator_script.run(generator_script_cmd_line('scaffold_for_view', ['--view', 'auto_complete']))
|
130
150
|
end
|
131
151
|
end
|
132
152
|
end
|
133
153
|
|
134
|
-
context "A Rails generator script" do
|
135
|
-
setup do
|
136
|
-
setup_test_model
|
137
|
-
@generator_script = Rails::Generator::Scripts::Generate.new
|
138
|
-
end
|
139
|
-
|
140
|
-
should "not perform any actions when run on the scaffold_for_view generator with no auto_complete field" do
|
141
|
-
Rails::Generator::Commands::Create.any_instance.expects(:directory).never
|
142
|
-
Rails::Generator::Commands::Create.any_instance.expects(:template).never
|
143
|
-
Rails::Generator::Commands::Create.any_instance.expects(:route_resources).never
|
144
|
-
Rails::Generator::Commands::Create.any_instance.expects(:file).never
|
145
|
-
Rails::Generator::Commands::Create.any_instance.expects(:route).never
|
146
|
-
Rails::Generator::Base.logger.stubs(:error)
|
147
|
-
Rails::Generator::Base.logger.stubs(:route)
|
148
|
-
@generator_script.run(generator_script_cmd_line('scaffold_for_view', ['--view', 'auto_complete']))
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
154
|
end
|
@@ -1,14 +1,14 @@
|
|
1
|
-
<h1>Editing
|
1
|
+
<h1>Editing test_model</h1>
|
2
2
|
|
3
|
-
<% form_for(@
|
3
|
+
<% form_for(@test_model) do |f| %>
|
4
4
|
<%= f.error_messages %>
|
5
5
|
<p>
|
6
6
|
<%= f.label :first_name %><br />
|
7
|
-
<%= text_field_with_auto_complete :
|
7
|
+
<%= text_field_with_auto_complete :test_model, :first_name, {}, { :method => :get } %>
|
8
8
|
</p>
|
9
9
|
<p>
|
10
10
|
<%= f.label :last_name %><br />
|
11
|
-
<%= text_field_with_auto_complete :
|
11
|
+
<%= text_field_with_auto_complete :test_model, :last_name, {}, { :method => :get } %>
|
12
12
|
</p>
|
13
13
|
<p>
|
14
14
|
<%= f.label :address %><br />
|
@@ -23,5 +23,5 @@
|
|
23
23
|
</p>
|
24
24
|
<% end %>
|
25
25
|
|
26
|
-
<%= link_to 'Show', @
|
27
|
-
<%= link_to 'Back',
|
26
|
+
<%= link_to 'Show', @test_model %> |
|
27
|
+
<%= link_to 'Back', test_models_path %>
|
@@ -1,5 +1,5 @@
|
|
1
1
|
ActionController::Routing::Routes.draw do |map|
|
2
|
-
map.connect '
|
2
|
+
map.connect 'auto_complete_for_test_model_address', :controller => 'test_models', :action => 'auto_complete_for_test_model_address'
|
3
3
|
|
4
4
|
# The priority is based upon order of creation: first created -> highest priority.
|
5
5
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<h1>Listing
|
1
|
+
<h1>Listing test_models</h1>
|
2
2
|
|
3
3
|
<table>
|
4
4
|
<tr>
|
@@ -8,19 +8,19 @@
|
|
8
8
|
<th>Some flag</th>
|
9
9
|
</tr>
|
10
10
|
|
11
|
-
<% @
|
11
|
+
<% @test_models.each do |test_model| %>
|
12
12
|
<tr>
|
13
|
-
<td><%=h
|
14
|
-
<td><%=h
|
15
|
-
<td><%=h
|
16
|
-
<td><%=h
|
17
|
-
<td><%= link_to 'Show',
|
18
|
-
<td><%= link_to 'Edit',
|
19
|
-
<td><%= link_to 'Destroy',
|
13
|
+
<td><%=h test_model.first_name %></td>
|
14
|
+
<td><%=h test_model.last_name %></td>
|
15
|
+
<td><%=h test_model.address %></td>
|
16
|
+
<td><%=h test_model.some_flag %></td>
|
17
|
+
<td><%= link_to 'Show', test_model %></td>
|
18
|
+
<td><%= link_to 'Edit', edit_test_model_path(test_model) %></td>
|
19
|
+
<td><%= link_to 'Destroy', test_model, :confirm => 'Are you sure?', :method => :delete %></td>
|
20
20
|
</tr>
|
21
21
|
<% end %>
|
22
22
|
</table>
|
23
23
|
|
24
24
|
<br />
|
25
25
|
|
26
|
-
<%= link_to 'New
|
26
|
+
<%= link_to 'New test_model', new_test_model_path %>
|
@@ -1,14 +1,14 @@
|
|
1
|
-
<h1>New
|
1
|
+
<h1>New test_model</h1>
|
2
2
|
|
3
|
-
<% form_for(@
|
3
|
+
<% form_for(@test_model) do |f| %>
|
4
4
|
<%= f.error_messages %>
|
5
5
|
<p>
|
6
6
|
<%= f.label :first_name %><br />
|
7
|
-
<%= text_field_with_auto_complete :
|
7
|
+
<%= text_field_with_auto_complete :test_model, :first_name, {}, { :method => :get } %>
|
8
8
|
</p>
|
9
9
|
<p>
|
10
10
|
<%= f.label :last_name %><br />
|
11
|
-
<%= text_field_with_auto_complete :
|
11
|
+
<%= text_field_with_auto_complete :test_model, :last_name, {}, { :method => :get } %>
|
12
12
|
</p>
|
13
13
|
<p>
|
14
14
|
<%= f.label :address %><br />
|
@@ -23,4 +23,4 @@
|
|
23
23
|
</p>
|
24
24
|
<% end %>
|
25
25
|
|
26
|
-
<%= link_to 'Back',
|
26
|
+
<%= link_to 'Back', test_models_path %>
|
@@ -1,23 +1,23 @@
|
|
1
1
|
<p>
|
2
2
|
<b>First name:</b>
|
3
|
-
<%=h @
|
3
|
+
<%=h @test_model.first_name %>
|
4
4
|
</p>
|
5
5
|
|
6
6
|
<p>
|
7
7
|
<b>Last name:</b>
|
8
|
-
<%=h @
|
8
|
+
<%=h @test_model.last_name %>
|
9
9
|
</p>
|
10
10
|
|
11
11
|
<p>
|
12
12
|
<b>Address:</b>
|
13
|
-
<%=h @
|
13
|
+
<%=h @test_model.address %>
|
14
14
|
</p>
|
15
15
|
|
16
16
|
<p>
|
17
17
|
<b>Some flag:</b>
|
18
|
-
<%=h @
|
18
|
+
<%=h @test_model.some_flag %>
|
19
19
|
</p>
|
20
20
|
|
21
21
|
|
22
|
-
<%= link_to 'Edit',
|
23
|
-
<%= link_to 'Back',
|
22
|
+
<%= link_to 'Edit', edit_test_model_path(@test_model) %> |
|
23
|
+
<%= link_to 'Back', test_models_path %>
|
@@ -4,7 +4,7 @@
|
|
4
4
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
5
5
|
<head>
|
6
6
|
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
|
7
|
-
<title>
|
7
|
+
<title>TestModels: <%= controller.action_name %></title>
|
8
8
|
<%= stylesheet_link_tag 'scaffold' %>
|
9
9
|
<%= javascript_include_tag :defaults %>
|
10
10
|
</head>
|
@@ -0,0 +1,89 @@
|
|
1
|
+
class TestModelsController < ApplicationController
|
2
|
+
|
3
|
+
auto_complete_for :test_model, :first_name
|
4
|
+
auto_complete_for :test_model, :last_name
|
5
|
+
|
6
|
+
# GET /test_models
|
7
|
+
# GET /test_models.xml
|
8
|
+
def index
|
9
|
+
@test_models = TestModel.all
|
10
|
+
|
11
|
+
respond_to do |format|
|
12
|
+
format.html # index.html.erb
|
13
|
+
format.xml { render :xml => @test_models }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# GET /test_models/1
|
18
|
+
# GET /test_models/1.xml
|
19
|
+
def show
|
20
|
+
@test_model = TestModel.find(params[:id])
|
21
|
+
|
22
|
+
respond_to do |format|
|
23
|
+
format.html # show.html.erb
|
24
|
+
format.xml { render :xml => @test_model }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# GET /test_models/new
|
29
|
+
# GET /test_models/new.xml
|
30
|
+
def new
|
31
|
+
@test_model = TestModel.new
|
32
|
+
|
33
|
+
respond_to do |format|
|
34
|
+
format.html # new.html.erb
|
35
|
+
format.xml { render :xml => @test_model }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# GET /test_models/1/edit
|
40
|
+
def edit
|
41
|
+
@test_model = TestModel.find(params[:id])
|
42
|
+
end
|
43
|
+
|
44
|
+
# POST /test_models
|
45
|
+
# POST /test_models.xml
|
46
|
+
def create
|
47
|
+
@test_model = TestModel.new(params[:test_model])
|
48
|
+
|
49
|
+
respond_to do |format|
|
50
|
+
if @test_model.save
|
51
|
+
flash[:notice] = 'TestModel was successfully created.'
|
52
|
+
format.html { redirect_to(@test_model) }
|
53
|
+
format.xml { render :xml => @test_model, :status => :created, :location => @test_model }
|
54
|
+
else
|
55
|
+
format.html { render :action => "new" }
|
56
|
+
format.xml { render :xml => @test_model.errors, :status => :unprocessable_entity }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# PUT /test_models/1
|
62
|
+
# PUT /test_models/1.xml
|
63
|
+
def update
|
64
|
+
@test_model = TestModel.find(params[:id])
|
65
|
+
|
66
|
+
respond_to do |format|
|
67
|
+
if @test_model.update_attributes(params[:test_model])
|
68
|
+
flash[:notice] = 'TestModel was successfully updated.'
|
69
|
+
format.html { redirect_to(@test_model) }
|
70
|
+
format.xml { head :ok }
|
71
|
+
else
|
72
|
+
format.html { render :action => "edit" }
|
73
|
+
format.xml { render :xml => @test_model.errors, :status => :unprocessable_entity }
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# DELETE /test_models/1
|
79
|
+
# DELETE /test_models/1.xml
|
80
|
+
def destroy
|
81
|
+
@test_model = TestModel.find(params[:id])
|
82
|
+
@test_model.destroy
|
83
|
+
|
84
|
+
respond_to do |format|
|
85
|
+
format.html { redirect_to(test_models_url) }
|
86
|
+
format.xml { head :ok }
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|