aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails_generator/generators/components/scaffold/templates/controller.rb
diff options
context:
space:
mode:
Diffstat (limited to 'railties/lib/rails_generator/generators/components/scaffold/templates/controller.rb')
-rw-r--r--railties/lib/rails_generator/generators/components/scaffold/templates/controller.rb55
1 files changed, 55 insertions, 0 deletions
diff --git a/railties/lib/rails_generator/generators/components/scaffold/templates/controller.rb b/railties/lib/rails_generator/generators/components/scaffold/templates/controller.rb
new file mode 100644
index 0000000000..c409284cb1
--- /dev/null
+++ b/railties/lib/rails_generator/generators/components/scaffold/templates/controller.rb
@@ -0,0 +1,55 @@
+class <%= controller_class_name %>Controller < ApplicationController
+<% unless suffix -%>
+
+ def index
+ list
+ render_action 'list'
+ end
+<% end -%>
+
+<% for action in unscaffolded_actions -%>
+ def <%= action %><%= suffix %>
+ end
+
+<% end -%>
+ def list<%= suffix %>
+ @<%= plural_name %> = <%= class_name %>.find_all
+ end
+
+ def show<%= suffix %>
+ @<%= singular_name %> = <%= class_name %>.find(@params['id'])
+ end
+
+ def new<%= suffix %>
+ @<%= singular_name %> = <%= class_name %>.new
+ end
+
+ def create<%= suffix %>
+ @<%= singular_name %> = <%= class_name %>.new(@params['<%= singular_name %>'])
+ if @<%= singular_name %>.save
+ flash['notice'] = '<%= class_name %> was successfully created.'
+ redirect_to :action => 'list<%= suffix %>'
+ else
+ render_action 'new<%= suffix %>'
+ end
+ end
+
+ def edit<%= suffix %>
+ @<%= singular_name %> = <%= class_name %>.find(@params['id'])
+ end
+
+ def update
+ @<%= singular_name %> = <%= class_name %>.find(@params['<%= singular_name %>']['id'])
+ if @<%= singular_name %>.update_attributes(@params['<%= singular_name %>'])
+ flash['notice'] = '<%= class_name %> was successfully updated.'
+ redirect_to :action => 'show<%= suffix %>', :id => @<%= singular_name %>.id
+ else
+ render_action 'edit<%= suffix %>'
+ end
+ end
+
+ def destroy<%= suffix %>
+ <%= class_name %>.find(@params['id']).destroy
+ redirect_to :action => 'list<%= suffix %>'
+ end
+end