开发者

Rails Basic Question about Devise

in devise, the forms look like this:

form_for(:resource, @resource, :url => edit_user(开发者_StackOverflow中文版resource), :html => {:method=> put}) do |f|

but I'm wondering, does it have to include method => put? Isn't REST supposed to have taken care of that already?

I've tried using form_for(@resource) but it does not get the edit user path. I think I am missing something here. Any help will be very much helpful. Thanks!


One of there rails guides talks about this, here is a snippet:

The Rails framework encourages RESTful design of your applications, which means you’ll be making a lot of “PUT” and “DELETE” requests (besides “GET” and “POST”). However, most browsers don’t support methods other than “GET” and “POST” when it comes to submitting forms.

Rails works around this issue by emulating other methods over POST with a hidden input named “_method”, which is set to reflect the desired method...

You populate this hidden input using :html => {:method=> put} this gives rails a bit of hint. Using this hint and the url you're submitting to rails can work out which of the restful action to submit the form to.

Have a read of that rails guide that I linked to, things should become a lot clearer after that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜