[LRUG] map.resources and Recipe for consolidating controllers

Simon Sebright simonsebright at hotmail.com
Wed Nov 5 08:00:40 PST 2008


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20081105/ee8c17bf/attachment-0003.html>


More information about the Chat mailing list