<% form_ tag user_path(@user), :method => :put do %>
那是我的表单,所以我希望它访问我的 UsersController 的更新方法,我设置了 map.resources :users ,并生成了 RESTful 路径:
users GET /users(.:format) {:action=>"index", :controller=>"users"}
POST /users(.:format) {:action=>"create",:controller=>"users"}
new_ user GET /users/new(.:format) {:action=>"new", :controller=>"users"}
edit_user GET /users/:id/edit(.:format) {:action=>"edit", :controller=>"users"}
user GET /users/:id(.:format) {:action=>"show", :controller=>"users"}
PUT /users/:id(.:format) {:action=>"update", :controller=>"users"}
DELETE /users/:id(.:format) {:action=>"destroy", :controller=>"users"}
所以我尝试使用 PUT HTTP 方法发送到 user_path(@user),它返回:
Unknown action
No action responded to 1. Actions: create, destroy, edit, index, logged?, new, show and update
很明显我不知道如何进行这项工作,所以在此先感谢。
最佳答案
如果您正在使用 RESTful 资源(您应该使用),请尝试使用 form_for
而不是 form_tag
... 完整设置如下:
<% form_for :user, @user, :url=>user_path(@user), :html=>{:method=>:put} do |f| %>
#this scopes the form elements to the @user object, eg.
<%= f.text_field :first_name %>
<% end %>
查看 API docs了解更多。
关于ruby-on-rails - Rails,在尝试使用 put http 方法的表单中出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1151331/