<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>On 5 Nov 2008, at 16:00, Simon Sebright wrote:</div><div><br class="Apple-interchange-newline"><blockquote type="cite"> <div id="MailContainerBody" style="PADDING-RIGHT: 10px; PADDING-LEFT: 10px; PADDING-TOP: 15px" bgcolor="#ffffff" leftmargin="0" topmargin="0" canvastabstop="true" name="Compose message area"> <div><font face="Arial" size="2">Hi,</font></div> <div><font face="Arial" size="2"></font> </div> <div><font face="Arial" size="2">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.</font></div> <div><font face="Arial" size="2"></font> </div> <div><font face="Arial" size="2">This gives rise to new, edit, update and create as standard actions for this model.</font></div> <div><font face="Arial" size="2"></font> </div> <div><font face="Arial" size="2">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:</font></div> <div><font face="Arial" size="2"></font> </div> <div><font face="Arial" size="2">@it = MyModel.find_by_id( params[:id] ) ¦¦ MyModel.new</font></div> <div><font face="Arial" size="2"></font> </div> <div><font face="Arial" size="2">if request.post?</font></div> <div> <font face="Arial" size="2">... including save with params[:it]</font></div> <div><font face="Arial" size="2">end</font></div> <div><font face="Arial" size="2"></font> </div> <div><font face="Arial" size="2">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.</font></div> <div><font face="Arial" size="2"></font> </div> <div><font face="Arial" size="2">Anyone else seen that, or am I missing something daft?</font></div> <div><font face="Arial" size="2"></font> </div> <div><font face="Arial" size="2">TIA,</font></div> <div><font face="Arial" size="2">Simon</font></div></div> _______________________________________________<br>Chat mailing list<br><a href="mailto:Chat@lists.lrug.org">Chat@lists.lrug.org</a><br>http://lists.lrug.org/listinfo.cgi/chat-lrug.org<br></blockquote></div><br><div><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div><br class="Apple-interchange-newline">On 5 Nov 2008, at 16:07, James Smith wrote:</div><blockquote type="cite"><div>Hi,<br><br>Neat though it is, that recipe isn't really appropriate to the<br>new-style map.resources stuff, as it does all the routing for you and<br>expects new, edit, update, and create actions to be implemented. I<br>wouldn't really recommend fighting against that... I'd stick with<br>separate actions.<br><br>I have an old 1.2 app which uses that recipe all over the place, and<br>it's going to be a right pain to change to a resource-based approach.<br><br>cheers,<br>James<br>_______________________________________________<br></div></blockquote><br></div><div>Hey,</div><div><br></div><div>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 ..</div><div><br></div><div>I often use Hampton Catlin's make_resourceful to abstract my controllers, and I think it works splendidly.</div><div><br></div><div><a href="http://github.com/hcatlin/make_resourceful/tree/master">http://github.com/hcatlin/make_resourceful/tree/master</a></div><div><br></div><div>It's nice and easy to extend for your edge cases ..</div><div><br></div><div>Cheers,</div><div>Jase.</div></div></div></body></html>