Forum: Ruby on Rails modifying scaffold method

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Joe Van D. (Guest)
on 2006-02-03 11:49
(Received via mailing list)
I've made the following changes to scaffolding.rb.  Is it possible to
put those changes into some type of a plugin or helper or something,
instead of directly modifying the Rails source?

(and, btw, I think pagination should be removed from scaffolding.  And
deletes should only happen on post requests.  That's essentially what
I've changed).


Index: vendor/rails/actionpack/lib/action_controller/scaffolding.rb
--- vendor/rails/actionpack/lib/action_controller/scaffolding.rb
 (revision 125)
+++ vendor/rails/actionpack/lib/action_controller/scaffolding.rb
 (working copy)
@@ -99,7 +99,7 @@

         module_eval <<-"end_eval", __FILE__, __LINE__
           def list#{suffix}
-            @#{singular_name}_pages, @#{plural_name} = paginate
:#{plural_name}, :per_page => 10
+            @#{plural_name} = #{class_name}.find(:all)
             render#{suffix}_scaffold "list#{suffix}"

@@ -109,8 +109,12 @@

           def destroy#{suffix}
-            #{class_name}.find(params[:id]).destroy
-            redirect_to :action => "list#{suffix}"
+            @#{ singular_name } = #{ class_name }.find(params[:id])
+            if
+              @#{ singular_name}.destroy
+              flash[:notice] = "#{ class_name } was deleted."
+              redirect_to :action => "list#{suffix}"
+            end

           def new#{suffix}
Siva J. (Guest)
on 2006-02-04 17:24
(Received via mailing list)
Hey Joe:
scaffolding works great to show a demo of how rails is cool :)

But when it comes to real application , we always end up changing those
classes. So use scaffolding as a starting point. Dont hesitate to change
BUT REMEMBER to back ur changes with unit and functional tests)

--Siva J.
My First Rails Project.
Education Through Collabration
This topic is locked and can not be replied to.