Chris
2006-Jul-26 17:03 UTC
[Rails] Can we have have protected methods in our REST controllers?
I gotta be quick, sos if it seems rushed. Latest word from DHH is that the REST conttrollers should only have 4 methods : Create, Update, New, Delete If you don''t know about DHH''s latest thing then leave now, or go read about it on his blog. Does this mean i can''t have private methods in my controller?? I have a method that create and new share. Thanks Chris -- Posted via http://www.ruby-forum.com/.
Josh Peek
2006-Jul-26 17:19 UTC
[Rails] Re: Can we have have protected methods in our REST controlle
Chris wrote:> Latest word from DHH is that the REST conttrollers should only have 4 > methods : > > Create, Update, New, Delete+ New and Edit> Does this mean i can''t have private methods in my controller?Nope. I''m guessing your using before_filter to DRY up some methods which is fine. -- Posted via http://www.ruby-forum.com/.
Chris
2006-Jul-26 20:06 UTC
[Rails] Re: Can we have have protected methods in our REST controlle
> Nope. I''m guessing your using before_filter to DRY up some methods which > is fine.how do you use before_filter to DRY up some methods but not all? -- Posted via http://www.ruby-forum.com/.
Josh Peek
2006-Jul-27 00:02 UTC
[Rails] Re: Can we have have protected methods in our REST controlle
Chris wrote:> how do you use before_filter to DRY up some methods but not all?Here is how you would DRY this up. def index @products = Product.find(:all) end def new @product = Product.new end def create @product = Product.create(params[:product]) end def show @product = Product.find(params[:id]) end def edit @product = Product.find(params[:id]) end def update @product = Product.find(params[:id]) @product.update_attributes(params[:product]) end def destroy @product = Product.find(params[:id]) @product.destroy end Becomes before_filter :find_product, :only => %w(show edit update destroy) def index @products = Product.find(:all) end def new @product = Product.new end def create end def show end def edit end def update @product.update_attributes(params[:product]) end def destroy @product.destroy end protected def find_product @product = Product.find(params[:id]) end When all your controllers are just CRUD, you notice that there are tons of things you can extract. -- Posted via http://www.ruby-forum.com/.
Chris
2006-Jul-27 09:23 UTC
[Rails] Re: Can we have have protected methods in our REST controlle
> When all your controllers are just CRUD, you notice that there are tons > of things you can extract.As i understand it with CRUD you will have more controllers, and controllers will frequently call each other. Lets say you have controller A and B... if B calls A''s action, then normally A would want to render its own template, but in this instance i dont want to do this, i want to return to whatever B wants to do. HOw do you get around this? -- Posted via http://www.ruby-forum.com/.
Josh Peek
2006-Jul-27 14:46 UTC
[Rails] Re: Can we have have protected methods in our REST controlle
Chris wrote:> Lets say you have controller A and B... if B calls A''s action, then > normally A would want to render its own template, but in this instance i > dont want to do this, i want to return to whatever B wants to do. HOw > do you get around this?Not really sure what your talking about? render :action => "B"? -- Posted via http://www.ruby-forum.com/.