ruby-on-rails - Rails,在尝试使用 put http 方法的表单中出现问题

标签 ruby-on-rails ruby forms rest

<% 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/

相关文章:

ruby-on-rails - MyGem :Module 的未定义方法 `configure'

ruby - Ruby 的 Array#to_a 方法有什么区别

javascript - 用于 phpmailer 的 php 表单提交使用 jquery ajax 发送邮件

javascript - 可拖动的 HTML <form> 输入

ruby-on-rails - 如何编写一个任务来在 Rails 3 中运行测试?

ruby-on-rails - Ruby on Rails 在 jsonb(哈希)中验证日期

Rails 应用程序中的 jquery 和 css : shifting a div to the left in response to a mouseover event not working

ruby-on-rails - Rails - 将小时和分钟转换为秒,然后将值分配给键

ruby - 要在 ruby​​ 中散列的数组

html - 如何防止输入字段在小型设备上超出父级的宽度?