【问题标题】:Form submit using 'form_tag' and namespaces in Ruby on Rails-3在 Ruby on Rails-3 中使用“form_tag”和命名空间提交表单
【发布时间】:2011-01-12 12:06:02
【问题描述】:

我正在尝试从“ROOT_RAILS/controllers/users/account_controller.rb”调用“更新”方法

  ...
end

def update
  ...
end

def ...

在“/ROOT_RAILS/views/users/accounts/account.rb”中使用“form_tag”:

<% form_tag ( users_account_path, :method => :post ) do %>
  <%= text_field_tag :name %>
  <%= text_field_tag :surname %>
  <%= submit_tag_tag "Update" %>  
<% end %>

并且在 'ROOT_RAILS/config/routes.rb' 中有一个命名空间

...
  namespace "users" do
    resources :accounts do
      collection do
        ...
      end
    end
  end
...

当我尝试提交此表单时,我有一个

No route matches "/users/accounts/2"

我哪里错了?


在“form_tag”中我尝试过

:controller => "users/accounts", :action => "update"

而不是

users_account_path

我认为是一样的。


如果我使用 ActiveRecord 表单有效:

<%= form_for(@account, :url => { :action => "update", :controller => "accounts" } }) do |f| %>
  ...

【问题讨论】:

    标签: ruby-on-rails forms namespaces ruby-on-rails-3 submit


    【解决方案1】:

    你试过了吗:

    users_accounts_path
    

    【讨论】:

    • 'users_accounts_path',就我而言,似乎与“创建”操作相匹配。
    • 我想这就是你想去的地方,因为你使用的是 post 方法?您可能知道这一点,但“rake routes”会显示您应用的所有可用路由。
    猜你喜欢
    • 2011-06-07
    • 1970-01-01
    • 1970-01-01
    • 2021-07-06
    • 2013-10-09
    • 2011-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多