[LRUG] map.resources and Recipe for consolidating controllers

Simon Sebright simonsebright at hotmail.com
Fri Nov 7 08:01:15 PST 2008


Thanks for the replies.  I stuck in an ¦¦ request.put? and that did the trick.

I suppose one could write a meta-function/macro for this and then when the change comes, just change that one function.

Regards,
Simon

From: jason.cale at mac.com
To: chat at lists.lrug.org
Date: Wed, 5 Nov 2008 16:12:55 +0000
Subject: Re: [LRUG] map.resources and Recipe for consolidating controllers

On 5 Nov 2008, at 16:00, Simon Sebright wrote:  Hi,   I'm a bit of a lurker, and have recently taken up Rails again.  I am experimenting with a standard controller for a simple model and have used the new RESTful stuff, and therefore have map.resources <mymodel> in the routes.rb file.   This gives rise to new, edit, update and create as standard actions for this model.   Then I read in Rails Recipes an item to consolidate these into one functio of the controller.  Only it doesn't quite work.  The basics are to do two checks:   @it = MyModel.find_by_id( params[:id] ) ¦¦ MyModel.new   if request.post?     ... including save with params[:it] end   With the update action, post? is not true.  Viewing the source, the form_for (@it) is generating /my_models as the destination and "post" as the method in the form html element.  Checking the server console output, I see it gets a URL with "PUT" as the HTTP verb.   Anyone else seen that, or am I missing something daft?   TIA, Simon _______________________________________________
Chat mailing list
Chat at lists.lrug.org
http://lists.lrug.org/listinfo.cgi/chat-lrug.org

On 5 Nov 2008, at 16:07, James Smith wrote:Hi,

Neat though it is, that recipe isn't really appropriate to the
new-style map.resources stuff, as it does all the routing for you and
expects new, edit, update, and create actions to be implemented. I
wouldn't really recommend fighting against that... I'd stick with
separate actions.

I have an old 1.2 app which uses that recipe all over the place, and
it's going to be a right pain to change to a resource-based approach.

cheers,
James
_______________________________________________

Hey,
ActionController these days has a request.put? which would equate to true for your update command .. but as James mentioned it might not be best way to go these days ..
I often use Hampton Catlin's make_resourceful to abstract my controllers, and I think it works splendidly.
http://github.com/hcatlin/make_resourceful/tree/master
It's nice and easy to extend for your edge cases ..
Cheers,Jase.
_________________________________________________________________
See the most popular videos on the web 
http://clk.atdmt.com/GBL/go/115454061/direct/01/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20081107/618ebd48/attachment.html>


More information about the Chat mailing list