Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

change default Rails scaffold to the new style using respond_with

  • Loading branch information...
commit 6b4f0f123f0dc08451cd9793d19b3e0fb7d28503 1 parent 55b721e
@danielvlopes authored
View
40 lib/templates/rails/scaffold_controller/controller.rb
@@ -0,0 +1,40 @@
+class <%= controller_class_name %>Controller < ApplicationController
+ respond_to :html, :json, :xml
+
+ def index
+ @<%= plural_table_name %> = <%= orm_class.all(class_name) %>
+ respond_with @<%= plural_table_name %>
+ end
+
+ def show
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
+ respond_with @<%= singular_table_name %>
+ end
+
+ def new
+ @<%= singular_table_name %> = <%= orm_class.build(class_name) %>
+ respond_with @<%= singular_table_name %>
+ end
+
+ def edit
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
+ end
+
+ def create
+ @<%= singular_table_name %> = <%= orm_class.build(class_name, "params[:#{singular_table_name}]") %>
+ flash[:notice] = '<%= human_name %> was successfully created.' if @<%= orm_instance.save %>
+ respond_with @<%= singular_table_name %>
+ end
+
+ def update
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
+ flash[:notice] = '<%= human_name %> was successfully updated.' if @<%= orm_instance.update_attributes("params[:#{singular_table_name}]") %>
+ respond_with @<%= singular_table_name %>
+ end
+
+ def destroy
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
+ @<%= orm_instance.destroy %>
+ respond_with @<%= singular_table_name %>, :location => <%= index_helper %>_url
+ end
+end
View
6 template.rb
@@ -25,7 +25,11 @@
get "http://github.com/danielvlopes/base_app/raw/master/public/images/ua_sf.jpg", "public/images/ua_sf.jpg"
get "http://github.com/rails/jquery-ujs/raw/master/src/rails.js", "public/javascripts/rails.js"
run "mkdir public/javascripts/lib public/javascripts/plugins"
-
+
+# scaffold customization
+run "mkdir lib/templates/rails/scaffold_controller"
+get "http://github.com/danielvlopes/base_app/raw/master/lib/templates/rails/scaffold_controller", "lib/templates/rails/scaffold_controller/controller.rb"
+
# test
generate "rspec:install"
generate "steak"
Please sign in to comment.
Something went wrong with that request. Please try again.