grimen-dry_scaffold 0.1.1
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/MIT-LICENSE +20 -0
- data/README.textile +303 -0
- data/Rakefile +47 -0
- data/TODO.textile +12 -0
- data/generators/USAGE +8 -0
- data/generators/dry_scaffold/dry_scaffold_generator.rb +250 -0
- data/generators/dry_scaffold/templates/controller_inherited_resources.rb +40 -0
- data/generators/dry_scaffold/templates/controller_standard.rb +242 -0
- data/generators/dry_scaffold/templates/controller_test_standard.rb +84 -0
- data/generators/dry_scaffold/templates/helper_standard.rb +3 -0
- data/generators/dry_scaffold/templates/helper_test_standard.rb +5 -0
- data/generators/dry_scaffold/templates/prototypes/controller_inherited_resources.rb +23 -0
- data/generators/dry_scaffold/templates/prototypes/controller_standard.rb +132 -0
- data/generators/dry_scaffold/templates/prototypes/controller_test_standard.rb +64 -0
- data/generators/dry_scaffold/templates/prototypes/helper_standard.rb +3 -0
- data/generators/dry_scaffold/templates/prototypes/helper_test_standard.rb +5 -0
- data/generators/dry_scaffold/templates/prototypes/layout.html.haml +19 -0
- data/generators/dry_scaffold/templates/prototypes/view__form.html.haml +3 -0
- data/generators/dry_scaffold/templates/prototypes/view__item.html.haml +9 -0
- data/generators/dry_scaffold/templates/prototypes/view_edit.html.haml +10 -0
- data/generators/dry_scaffold/templates/prototypes/view_index.html.haml +17 -0
- data/generators/dry_scaffold/templates/prototypes/view_new.html.haml +10 -0
- data/generators/dry_scaffold/templates/prototypes/view_show.html.haml +13 -0
- data/generators/dry_scaffold/templates/view__form.html.haml +13 -0
- data/generators/dry_scaffold/templates/view__item.html.haml +10 -0
- data/generators/dry_scaffold/templates/view_edit.html.haml +18 -0
- data/generators/dry_scaffold/templates/view_index.html.haml +20 -0
- data/generators/dry_scaffold/templates/view_layout.html.haml +19 -0
- data/generators/dry_scaffold/templates/view_new.html.haml +18 -0
- data/generators/dry_scaffold/templates/view_show.html.haml +13 -0
- data/rails/init.rb +3 -0
- data/tasks/dry_scaffold.rake +51 -0
- metadata +88 -0
@@ -0,0 +1,242 @@
|
|
1
|
+
class <%= controller_class_name %>Controller < ApplicationController
|
2
|
+
|
3
|
+
<% if actions -%>
|
4
|
+
before_filter :load_resource, :only => [<%= symbol_array_to_expression(actions & DryScaffoldGenerator::DEFAULT_MEMBER_AUTOLOAD_ACTIONS) %>]
|
5
|
+
<% end -%>
|
6
|
+
<% if actions -%>
|
7
|
+
before_filter :load_and_paginate_resources, :only => [<%= symbol_array_to_expression(actions & DryScaffoldGenerator::DEFAULT_COLLECTION_AUTOLOAD_ACTIONS) %>]
|
8
|
+
|
9
|
+
<% end -%>
|
10
|
+
<% if actions.include?(:index) -%>
|
11
|
+
<% formats.each do |_format| -%>
|
12
|
+
# GET /<%= plural_name %><%= ".#{_format}" unless _format == :html %>
|
13
|
+
<% end -%>
|
14
|
+
def index
|
15
|
+
respond_to do |format|
|
16
|
+
<% formats.each do |_format| -%>
|
17
|
+
<% case _format when :html then -%>
|
18
|
+
format.html # index.html.haml
|
19
|
+
<% when :js then -%>
|
20
|
+
format.js # index.js.rjs
|
21
|
+
<% when :xml, :json then -%>
|
22
|
+
format.<%= _format %> { render :<%= _format %> => @<%= plural_name %> }
|
23
|
+
<% when :yml, :yaml then -%>
|
24
|
+
format.yaml { render :text => @<%= plural_name %>.to_yaml, :content_type => :'text/yaml' }
|
25
|
+
<% when :txt, :text then -%>
|
26
|
+
format.txt { render :text => @<%= plural_name %>.to_s, :content_type => :text }
|
27
|
+
<% else -%>
|
28
|
+
format.<%= _format %> { }
|
29
|
+
<% end -%>
|
30
|
+
<% end -%>
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
<% end -%>
|
35
|
+
<% if actions.include?(:show) -%>
|
36
|
+
<% formats.each do |_format| -%>
|
37
|
+
# GET /<%= plural_name %>/:id<%= ".#{_format}" unless _format == :html %>
|
38
|
+
<% end -%>
|
39
|
+
def show
|
40
|
+
respond_to do |format|
|
41
|
+
<% formats.each do |_format| -%>
|
42
|
+
<% case _format when :html then -%>
|
43
|
+
format.html # show.html.haml
|
44
|
+
<% when :js then -%>
|
45
|
+
format.js # show.js.rjs
|
46
|
+
<% when :xml, :json then -%>
|
47
|
+
format.<%= _format %> { render :<%= _format %> => @<%= plural_name %> }
|
48
|
+
<% when :yml, :yaml then -%>
|
49
|
+
format.yaml { render :text => @<%= plural_name %>.to_yaml, :content_type => :'text/yaml' }
|
50
|
+
<% when :txt, :text then -%>
|
51
|
+
format.txt { render :text => @<%= plural_name %>.to_s, :content_type => :text }
|
52
|
+
<% else -%>
|
53
|
+
format.<%= _format %> { }
|
54
|
+
<% end -%>
|
55
|
+
<% end -%>
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
<% end -%>
|
60
|
+
<% if actions.include?(:new) -%>
|
61
|
+
<% formats.each do |_format| -%>
|
62
|
+
# GET /<%= plural_name %>/new<%= ".#{_format}" unless _format == :html %>
|
63
|
+
<% end -%>
|
64
|
+
def new
|
65
|
+
@<%= singular_name %> = <%= class_name %>.new
|
66
|
+
|
67
|
+
respond_to do |format|
|
68
|
+
<% formats.each do |_format| -%>
|
69
|
+
<% case _format when :html then -%>
|
70
|
+
format.html # new.html.haml
|
71
|
+
<% when :js then -%>
|
72
|
+
format.js # new.js.rjs
|
73
|
+
<% when :xml, :json then -%>
|
74
|
+
format.<%= _format %> { render :<%= _format %> => @<%= singular_name %> }
|
75
|
+
<% when :yml, :yaml then -%>
|
76
|
+
format.yaml { render :text => @<%= singular_name %>.to_yaml, :content_type => :'text/yaml' }
|
77
|
+
<% when :txt, :text then -%>
|
78
|
+
format.txt { render :text => @<%= singular_name %>.to_s, :content_type => :text }
|
79
|
+
<% else -%>
|
80
|
+
format.<%= _format %> { }
|
81
|
+
<% end -%>
|
82
|
+
<% end -%>
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
<% end -%>
|
87
|
+
<% if actions.include?(:edit) -%>
|
88
|
+
# GET /<%= plural_name %>/:id/edit
|
89
|
+
def edit
|
90
|
+
end
|
91
|
+
|
92
|
+
<% end -%>
|
93
|
+
<% if actions.include?(:create) -%>
|
94
|
+
<% formats.each do |_format| -%>
|
95
|
+
# POST /<%= plural_name %><%= ".#{_format}" unless _format == :html %>
|
96
|
+
<% end -%>
|
97
|
+
def create
|
98
|
+
@<%= singular_name %> = <%= class_name %>.new(params[:<%= singular_name %>])
|
99
|
+
|
100
|
+
respond_to do |format|
|
101
|
+
if @<%= singular_name %>.save
|
102
|
+
flash[:notice] = '<%= singular_name.humanize %> was successfully created.'
|
103
|
+
<% formats.each do |_format| -%>
|
104
|
+
<% case _format when :html then -%>
|
105
|
+
format.html { redirect_to(@<%= singular_name %>) }
|
106
|
+
<% when :js then -%>
|
107
|
+
format.js # create.js.rjs
|
108
|
+
<% when :xml, :json then -%>
|
109
|
+
format.<%= _format %> { render :<%= _format %> => @<%= singular_name %>, :status => :created, :location => @<%= singular_name %> }
|
110
|
+
<% when :yml, :yaml then -%>
|
111
|
+
format.yaml { render :text => @<%= singular_name %>.to_yaml, :content_type => :'text/yaml', :status => :created, :location => @<%= singular_name %> }
|
112
|
+
<% when :txt, :text then -%>
|
113
|
+
format.txt { render :text => @<%= singular_name %>.to_s, :content_type => :text, :status => :created, :location => @<%= singular_name %> }
|
114
|
+
<% else -%>
|
115
|
+
format.<%= _format %> { }
|
116
|
+
<% end -%>
|
117
|
+
<% end -%>
|
118
|
+
else
|
119
|
+
#flash[:error] = '<%= singular_name.humanize %> could not be created.'
|
120
|
+
<% formats.each do |_format| -%>
|
121
|
+
<% case _format when :html then -%>
|
122
|
+
format.html { render 'new' }
|
123
|
+
<% when :js then -%>
|
124
|
+
format.js # create.js.rjs
|
125
|
+
<% when :xml, :json then -%>
|
126
|
+
format.<%= _format %> { render :<%= _format %> => @<%= singular_name %>.errors, :status => :unprocessable_entity }
|
127
|
+
<% when :yml, :yaml then -%>
|
128
|
+
format.yaml { render :text => @<%= singular_name %>.errors.to_yaml, :content_type => :'text/yaml', :status => :unprocessable_entity }
|
129
|
+
<% when :txt, :text then -%>
|
130
|
+
format.txt { render :text => @<%= singular_name %>.errors.to_s, :content_type => :text, :status => :unprocessable_entity }
|
131
|
+
<% else -%>
|
132
|
+
format.<%= _format %> { }
|
133
|
+
<% end -%>
|
134
|
+
<% end -%>
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
<% end -%>
|
140
|
+
<% if actions.include?(:update) -%>
|
141
|
+
<% formats.each do |_format| -%>
|
142
|
+
# PUT /<%= plural_name %>/:id<%= ".#{_format}" unless _format == :html %>
|
143
|
+
<% end -%>
|
144
|
+
def update
|
145
|
+
respond_to do |format|
|
146
|
+
if @<%= singular_name %>.update_attributes(params[:<%= singular_name %>])
|
147
|
+
<% formats.each do |_format| -%>
|
148
|
+
<% case _format when :html then -%>
|
149
|
+
format.html { redirect_to(@<%= singular_name %>) }
|
150
|
+
<% when :js then -%>
|
151
|
+
format.js # update.js.rjs
|
152
|
+
<% when :xml, :json, :yml, :yaml, :txt, :text then -%>
|
153
|
+
format.<%= _format %> { head :ok }
|
154
|
+
<% else -%>
|
155
|
+
format.<%= _format %> { head :ok }
|
156
|
+
<% end -%>
|
157
|
+
<% end -%>
|
158
|
+
else
|
159
|
+
#flash[:error] = '<%= singular_name.humanize %> could not be updated.'
|
160
|
+
<% formats.each do |_format| -%>
|
161
|
+
<% case _format when :html then -%>
|
162
|
+
format.html { render 'edit' }
|
163
|
+
<% when :js then -%>
|
164
|
+
format.js # update.js.rjs
|
165
|
+
<% when :xml, :json then -%>
|
166
|
+
format.<%= _format %> { render :<%= _format %> => @<%= singular_name %>.errors, :status => :unprocessable_entity }
|
167
|
+
<% when :yml, :yaml then -%>
|
168
|
+
format.yaml { render :text => @<%= singular_name %>.errors.to_yaml, :status => :unprocessable_entity }
|
169
|
+
<% when :txt, :text then -%>
|
170
|
+
format.txt { render :text => @<%= singular_name %>.errors.to_s, :status => :unprocessable_entity }
|
171
|
+
<% else -%>
|
172
|
+
format.<%= _format %> { head :unprocessable_entity }
|
173
|
+
<% end -%>
|
174
|
+
<% end -%>
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
<% end -%>
|
180
|
+
<% if actions.include?(:destroy) -%>
|
181
|
+
<% formats.each do |_format| -%>
|
182
|
+
# DELETE /<%= plural_name %>/:id<%= ".#{_format}" unless _format == :html %>
|
183
|
+
<% end -%>
|
184
|
+
def destroy
|
185
|
+
respond_to do |format|
|
186
|
+
if @<%= singular_name %>.destroy
|
187
|
+
flash[:notice] = '<%= singular_name.humanize %> was successfully destroyed.'
|
188
|
+
<% formats.each do |_format| -%>
|
189
|
+
<% case _format when :html then -%>
|
190
|
+
format.html { redirect_to(<%= plural_name %>_url) }
|
191
|
+
<% when :js then -%>
|
192
|
+
format.js # destroy.js.rjs
|
193
|
+
<% when :xml, :json, :yml, :yaml, :txt, :text then -%>
|
194
|
+
format.<%= _format %> { head :ok }
|
195
|
+
<% else -%>
|
196
|
+
format.<%= _format %> { head :ok }
|
197
|
+
<% end -%>
|
198
|
+
<% end -%>
|
199
|
+
else
|
200
|
+
flash[:error] = '<%= singular_name.humanize %> could not be destroyed.'
|
201
|
+
<% formats.each do |_format| -%>
|
202
|
+
<% case _format when :html then -%>
|
203
|
+
format.html { redirect_to(<%= singular_name %>_url(@<%= singular_name %>)) }
|
204
|
+
<% when :js then -%>
|
205
|
+
format.js # destroy.js.rjs
|
206
|
+
<% when :xml, :json, :yml, :yaml, :txt, :text then -%>
|
207
|
+
format.<%= _format %> { head :unprocessable_entity }
|
208
|
+
<% else -%>
|
209
|
+
format.<%= _format %> { head :unprocessable_entity }
|
210
|
+
<% end -%>
|
211
|
+
<% end -%>
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
<% end -%>
|
217
|
+
<% (actions - DryScaffoldGenerator::DEFAULT_CONTROLLER_ACTIONS).each do |action| -%>
|
218
|
+
# GET /<%= plural_name %>/<%= action.to_s %>
|
219
|
+
def <%= action.to_s %>
|
220
|
+
end
|
221
|
+
|
222
|
+
<% end -%>
|
223
|
+
protected
|
224
|
+
|
225
|
+
def collection
|
226
|
+
<% if options[:pagination] -%>
|
227
|
+
paginate_options ||= {}
|
228
|
+
paginate_options[:page] ||= (params[:page] || 1)
|
229
|
+
paginate_options[:per_page] ||= (params[:per_page] || 20)
|
230
|
+
@collection = @<%= plural_name %> ||= <%= class_name %>.paginate(paginate_options)
|
231
|
+
<% else -%>
|
232
|
+
@collection = @<%= plural_name %> ||= <%= class_name %>.all
|
233
|
+
<% end -%>
|
234
|
+
end
|
235
|
+
alias :load_and_paginate_resources :collection
|
236
|
+
|
237
|
+
def resource
|
238
|
+
@resource = @<%= singular_name %> ||= <%= class_name %>.find(params[:id])
|
239
|
+
end
|
240
|
+
alias :load_resource :resource
|
241
|
+
|
242
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class <%= controller_class_name %>ControllerTest < ActionController::TestCase
|
4
|
+
|
5
|
+
<% if actions.include?(:create) -%>
|
6
|
+
test "create" do
|
7
|
+
<%= class_name %>.any_instance.expects(:save).returns(true)
|
8
|
+
post :create, :<%= file_name %> => { }
|
9
|
+
assert_response :redirect
|
10
|
+
end
|
11
|
+
|
12
|
+
test "create_with_failure" do
|
13
|
+
<%= class_name %>.any_instance.expects(:save).returns(false)
|
14
|
+
post :create, :<%= file_name %> => { }
|
15
|
+
assert_template 'new'
|
16
|
+
end
|
17
|
+
|
18
|
+
<% end -%>
|
19
|
+
<% if actions.include?(:destroy) -%>
|
20
|
+
test "destroy" do
|
21
|
+
<%= class_name %>.any_instance.expects(:destroy).returns(true)
|
22
|
+
delete :destroy, :id => <%= table_name %>(:one).to_param
|
23
|
+
assert_not_nil flash[:notice]
|
24
|
+
assert_response :redirect
|
25
|
+
end
|
26
|
+
|
27
|
+
test "destroy_with_failure" do
|
28
|
+
<%= class_name %>.any_instance.expects(:destroy).returns(false)
|
29
|
+
delete :destroy, :id => <%= table_name %>(:one).to_param
|
30
|
+
assert_not_nil flash[:error]
|
31
|
+
assert_response :redirect
|
32
|
+
end
|
33
|
+
|
34
|
+
<% end -%>
|
35
|
+
<% if actions.include?(:edit) -%>
|
36
|
+
test "edit" do
|
37
|
+
get :edit, :id => <%= table_name %>(:one).to_param
|
38
|
+
assert_response :success
|
39
|
+
end
|
40
|
+
|
41
|
+
<% end -%>
|
42
|
+
<% if actions.include?(:index) -%>
|
43
|
+
test "index" do
|
44
|
+
get :index
|
45
|
+
assert_response :success
|
46
|
+
assert_not_nil assigns(:<%= table_name %>)
|
47
|
+
end
|
48
|
+
|
49
|
+
<% end -%>
|
50
|
+
<% if actions.include?(:new) -%>
|
51
|
+
test "new" do
|
52
|
+
get :new
|
53
|
+
assert_response :success
|
54
|
+
end
|
55
|
+
|
56
|
+
<% end -%>
|
57
|
+
<% if actions.include?(:show) -%>
|
58
|
+
test "show" do
|
59
|
+
get :show, :id => <%= table_name %>(:one).to_param
|
60
|
+
assert_response :success
|
61
|
+
end
|
62
|
+
|
63
|
+
<% end -%>
|
64
|
+
<% if actions.include?(:update) -%>
|
65
|
+
test "update" do
|
66
|
+
<%= class_name %>.any_instance.expects(:save).returns(true)
|
67
|
+
put :update, :id => <%= table_name %>(:one).to_param, :<%= file_name %> => { }
|
68
|
+
assert_response :redirect
|
69
|
+
end
|
70
|
+
|
71
|
+
test "update_with_failure" do
|
72
|
+
<%= class_name %>.any_instance.expects(:save).returns(false)
|
73
|
+
put :update, :id => <%= table_name %>(:one).to_param, :<%= file_name %> => { }
|
74
|
+
assert_template 'edit'
|
75
|
+
end
|
76
|
+
|
77
|
+
<% end -%>
|
78
|
+
<% (actions - DryScaffoldGenerator::DEFAULT_CONTROLLER_ACTIONS).each do |action| -%>
|
79
|
+
test "<%= action.to_s %>" do
|
80
|
+
assert true
|
81
|
+
end
|
82
|
+
|
83
|
+
<% end -%>
|
84
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class ResourcesController < InheritedResources::Base
|
2
|
+
|
3
|
+
actions :index, :show, :new, :create, :edit, :update, :destroy
|
4
|
+
respond_to :html, :xml, :json
|
5
|
+
|
6
|
+
# GET /resources/custom_action
|
7
|
+
def custom_action
|
8
|
+
end
|
9
|
+
|
10
|
+
protected
|
11
|
+
|
12
|
+
def collection
|
13
|
+
paginate_options ||= {}
|
14
|
+
paginate_options[:page] ||= (params[:page] || 1)
|
15
|
+
paginate_options[:per_page] ||= (params[:per_page] || 20)
|
16
|
+
@collection = @resources ||= end_of_association_chain.paginate(paginate_options)
|
17
|
+
end
|
18
|
+
|
19
|
+
def resource
|
20
|
+
@resource = @resource ||= end_of_association_chain.find(params[:id])
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
class ResourcesController < ApplicationController
|
2
|
+
|
3
|
+
before_filter :load_resource, :only => [:show, :edit, :update, :destroy]
|
4
|
+
before_filter :load_and_paginate_resources, :only => [:index]
|
5
|
+
|
6
|
+
# GET /resources
|
7
|
+
# GET /resources.xml
|
8
|
+
# GET /resources.json
|
9
|
+
def index
|
10
|
+
respond_to do |format|
|
11
|
+
format.html # index.html.haml
|
12
|
+
#format.js # index.js.rjs
|
13
|
+
format.xml { render :xml => @resources }
|
14
|
+
format.json { render :json => @resources }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# GET /resources/:id
|
19
|
+
# GET /resources/:id.xml
|
20
|
+
# GET /resources/:id.json
|
21
|
+
def show
|
22
|
+
respond_to do |format|
|
23
|
+
format.html # show.html.haml
|
24
|
+
#format.js # show.js.rjs
|
25
|
+
format.xml { render :xml => @resource }
|
26
|
+
format.json { render :json => @resource }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# GET /resources/new
|
31
|
+
# GET /resources/new.xml
|
32
|
+
# GET /resources/new.json
|
33
|
+
def new
|
34
|
+
@resource = Resource.new
|
35
|
+
|
36
|
+
respond_to do |format|
|
37
|
+
format.html # new.html.haml
|
38
|
+
#format.js # new.js.rjs
|
39
|
+
format.xml { render :xml => @resource }
|
40
|
+
format.json { render :json => @resource }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# GET /resources/:id/edit
|
45
|
+
def edit
|
46
|
+
end
|
47
|
+
|
48
|
+
# POST /resources
|
49
|
+
# POST /resources.xml
|
50
|
+
# POST /resources.json
|
51
|
+
def create
|
52
|
+
@resource = Resource.new(params[:resource])
|
53
|
+
|
54
|
+
respond_to do |format|
|
55
|
+
if @resource.save
|
56
|
+
flash[:notice] = 'Resource was successfully created.'
|
57
|
+
format.html { redirect_to(@resource) }
|
58
|
+
#format.js # create.js.rjs
|
59
|
+
format.xml { render :xml => @resource, :status => :created, :location => @resource }
|
60
|
+
format.json { render :json => @resource, :status => :created, :location => @resource }
|
61
|
+
else
|
62
|
+
#flash[:error] = 'Resource could not be created.'
|
63
|
+
format.html { render 'new' }
|
64
|
+
#format.js # create.js.rjs
|
65
|
+
format.xml { render :xml => @resource.errors, :status => :unprocessable_entity }
|
66
|
+
format.json { render :json => @resource.errors, :status => :unprocessable_entity }
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# PUT /resources/:id
|
72
|
+
# PUT /resources/:id.xml
|
73
|
+
# PUT /resources/:id.json
|
74
|
+
def update
|
75
|
+
respond_to do |format|
|
76
|
+
if @resource.update_attributes(params[:resource])
|
77
|
+
flash[:notice] = 'Resource was successfully updated.'
|
78
|
+
format.html { redirect_to(@resource) }
|
79
|
+
#format.js # update.js.rjs
|
80
|
+
format.xml { head :ok }
|
81
|
+
format.json { head :ok }
|
82
|
+
else
|
83
|
+
#flash[:error] = 'Resource could not be updated.'
|
84
|
+
format.html { render 'edit' }
|
85
|
+
#format.js # update.js.rjs
|
86
|
+
format.xml { render :xml => @resource.errors, :status => :unprocessable_entity }
|
87
|
+
format.json { render :json => @resource.errors, :status => :unprocessable_entity }
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
# DELETE /resources/:id
|
93
|
+
# DELETE /resources/:id.xml
|
94
|
+
# DELETE /resources/:id.json
|
95
|
+
def destroy
|
96
|
+
respond_to do |format|
|
97
|
+
if @resource.destroy
|
98
|
+
flash[:notice] = 'Resource was successfully destroyed.'
|
99
|
+
format.html { redirect_to(resources_url) }
|
100
|
+
#format.js # destroy.js.rjs
|
101
|
+
format.xml { head :ok }
|
102
|
+
format.json { head :ok }
|
103
|
+
else
|
104
|
+
flash[:error] = 'Resource could not be destroyed.'
|
105
|
+
format.html { redirect_to(resource_url(@resource)) }
|
106
|
+
#format.js # destroy.js.rjs
|
107
|
+
format.xml { head :unprocessable_entity }
|
108
|
+
format.json { head :unprocessable_entity }
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
# GET /resources/custom_action
|
114
|
+
def custom_action
|
115
|
+
end
|
116
|
+
|
117
|
+
protected
|
118
|
+
|
119
|
+
def collection
|
120
|
+
paginate_options ||= {}
|
121
|
+
paginate_options[:page] ||= (params[:page] || 1)
|
122
|
+
paginate_options[:per_page] ||= (params[:per_page] || 20)
|
123
|
+
@collection = @resources ||= Resource.paginate(paginate_options)
|
124
|
+
end
|
125
|
+
alias :load_and_paginate_resources :collection
|
126
|
+
|
127
|
+
def resource
|
128
|
+
@resource = @resource = ||= Resource.find(params[:id])
|
129
|
+
end
|
130
|
+
alias :load_resource :resource
|
131
|
+
|
132
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class ResourceControllerTest < ActionController::TestCase
|
4
|
+
|
5
|
+
test "create" do
|
6
|
+
Resource.any_instance.expects(:save).returns(true)
|
7
|
+
post :create, :resource => { }
|
8
|
+
assert_response :redirect
|
9
|
+
end
|
10
|
+
|
11
|
+
test "create_with_failure" do
|
12
|
+
Resource.any_instance.expects(:save).returns(false)
|
13
|
+
post :create, :resource => { }
|
14
|
+
assert_template 'new'
|
15
|
+
end
|
16
|
+
|
17
|
+
test "destroy" do
|
18
|
+
Resource.any_instance.expects(:destroy).returns(true)
|
19
|
+
delete :destroy, :id => resources(:one).to_param
|
20
|
+
assert_not_nil flash[:notice]
|
21
|
+
assert_response :redirect
|
22
|
+
end
|
23
|
+
|
24
|
+
test "destroy_with_failure" do
|
25
|
+
Resource.any_instance.expects(:destroy).returns(false)
|
26
|
+
delete :destroy, :id => resources(:one).to_param
|
27
|
+
assert_not_nil flash[:error]
|
28
|
+
assert_response :redirect
|
29
|
+
end
|
30
|
+
|
31
|
+
test "edit" do
|
32
|
+
get :edit, :id => resources(:one).to_param
|
33
|
+
assert_response :success
|
34
|
+
end
|
35
|
+
|
36
|
+
test "index" do
|
37
|
+
get :index
|
38
|
+
assert_response :success
|
39
|
+
assert_not_nil assigns(:resources)
|
40
|
+
end
|
41
|
+
|
42
|
+
test "new" do
|
43
|
+
get :new
|
44
|
+
assert_response :success
|
45
|
+
end
|
46
|
+
|
47
|
+
test "show" do
|
48
|
+
get :show, :id => resources(:one).to_param
|
49
|
+
assert_response :success
|
50
|
+
end
|
51
|
+
|
52
|
+
test "update" do
|
53
|
+
Resource.any_instance.expects(:save).returns(true)
|
54
|
+
put :update, :id => resources(:one).to_param, :resource => { }
|
55
|
+
assert_response :redirect
|
56
|
+
end
|
57
|
+
|
58
|
+
test "update_with_failure" do
|
59
|
+
Resource.any_instance.expects(:save).returns(false)
|
60
|
+
put :update, :id => resources(:one).to_param, :resource => { }
|
61
|
+
assert_template 'edit'
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
!!! 1.1
|
2
|
+
|
3
|
+
%html{html_attrs(I18n.locale)}
|
4
|
+
%head
|
5
|
+
%title= "#{controller_class_name}: #{controller.action_name}"
|
6
|
+
|
7
|
+
= stylesheet_link_tag 'screen', :media => 'screen, projection'
|
8
|
+
= stylesheet_link_tag 'print', :media => 'print'
|
9
|
+
/[if IE]
|
10
|
+
= stylesheet_link_tag 'ie', :media => 'screen, projection'
|
11
|
+
= stylesheet_link_tag 'scaffold'
|
12
|
+
|
13
|
+
= javascript_link_tag :defaults
|
14
|
+
|
15
|
+
%body{:id => "#{controller.controller_name}_#{controller.action_name}", :class => "#{controller.controller_name}_controller #{controller.action_name}_action"}
|
16
|
+
|
17
|
+
%p.flash{:style => 'color: green'}= flash[:notice]
|
18
|
+
|
19
|
+
= yield
|
@@ -0,0 +1,9 @@
|
|
1
|
+
- content_tag_for(:tr, resource) do
|
2
|
+
%td.title= h resource.try(:title)
|
3
|
+
%td.description= h resource.try(:description)
|
4
|
+
%td.actions
|
5
|
+
= link_to 'Show', resource_url(resource)
|
6
|
+
|
|
7
|
+
= link_to 'Edit', edit_resource_url(resource)
|
8
|
+
|
|
9
|
+
= link_to 'Destroy', resource_url(resource), :confirm => 'Are you sure?', :method => :delete
|
@@ -0,0 +1,17 @@
|
|
1
|
+
%h1.heading
|
2
|
+
= 'Sections'
|
3
|
+
|
4
|
+
%p.actions
|
5
|
+
= link_to 'New resource', new_resource_url
|
6
|
+
|
7
|
+
%table
|
8
|
+
%thead.header
|
9
|
+
%tr
|
10
|
+
%th.title= 'Title'
|
11
|
+
%th.description= 'Description'
|
12
|
+
%th.actions= 'Actions'
|
13
|
+
%tbody.items.resources
|
14
|
+
- @collection.each do |resource|
|
15
|
+
= render 'item', :resource => resource
|
16
|
+
|
17
|
+
= will_paginate(@collection)
|
@@ -0,0 +1,13 @@
|
|
1
|
+
%h1.heading
|
2
|
+
= "Resource %s" % @resource.id
|
3
|
+
|
4
|
+
- content_tag_for(:dl, @resource) do
|
5
|
+
%dt.label= 'Title'
|
6
|
+
%dd.title= h @resource.try(:title)
|
7
|
+
%dt.label= 'Description'
|
8
|
+
%dd.description= h @resource.try(:description)
|
9
|
+
|
10
|
+
%p.actions
|
11
|
+
= link_to 'Edit', edit_resource_url(@resource)
|
12
|
+
|
|
13
|
+
= link_to 'Index', resources_url
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<% if options[:formtastic] -%>
|
2
|
+
- form.inputs do
|
3
|
+
<% attributes.each do |attribute| -%>
|
4
|
+
= form.input :<%= attribute.name %>, :label => '<%= attribute.name.humanize %>'
|
5
|
+
<% end -%>
|
6
|
+
<% else -%>
|
7
|
+
%fieldset
|
8
|
+
%dl
|
9
|
+
<% attributes.each do |attribute| -%>
|
10
|
+
%dt.label= form.label :<%= attribute.name %>, '<%= attribute.name.humanize %>'
|
11
|
+
%dd.<%= attribute.name %>= form.<%= attribute.field_type %> :<%= attribute.name %>
|
12
|
+
<% end -%>
|
13
|
+
<% end -%>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
- content_tag_for(:tr, <%= singular_name -%>, :class => cycle(:odd, :even)) do
|
2
|
+
<% attributes.each do |attribute| -%>
|
3
|
+
%td.<%= attribute.name %>= h <%= singular_name %>.try(:<%= attribute.name %>)
|
4
|
+
<% end -%>
|
5
|
+
%td.actions
|
6
|
+
= link_to 'Show', <%= singular_name %>
|
7
|
+
|
|
8
|
+
= link_to 'Edit', edit_<%= singular_name %>_url(<%= singular_name %>)
|
9
|
+
|
|
10
|
+
= link_to 'Destroy', <%= singular_name %>, :confirm => 'Are you sure?', :method => :delete
|