嵌套控制器/命名空间的路径助手

时间:2012-06-27 15:29:26

标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.1 routes nested-routes

我有路线结构:

  namespace :admin do
    resources :currencies
  end

rake路线输出:

admin_currencies     GET /admin/currencies(.:format) admin/currencies#index
                     POST /admin/currencies(.:format) admin/currencies#create
new_admin_currency   GET /admin/currencies/new(.:format) admin/currencies#new
edit_admin_currency  GET /admin/currencies/:id/edit(.:format) admin/currencies#edit
      admin_currency GET /admin/currencies/:id(.:format) admin/currencies#show
                     PUT /admin/currencies/:id(.:format) admin/currencies#update
                     DELETE /admin/currencies/:id(.:format) admin/currencies#destroy

Admin是一个命名空间。

脚手架生成的表格看起来像

= form_for @currency do |f|
  - if @currency.errors.any?
    #error_explanation
      %h2
        = pluralize(@currency.errors.count, "error")
        prohibited this currency from being saved:
      %ul
        - @currency.errors.full_messages.each do |msg|
          %li= msg
  .field
    = f.label :title
    %br/
    = f.text_field :title
  .field
    = f.label :iso_code
    %br/
    = f.text_field :iso_code
  .actions
    = f.submit

我已将= form_for @currency更改为= form_for admin_currencies_path(@currency)但由于表单操作仍然失败,因此/ admin / currency / new而非/ admin / currency。

我做错了什么?

感谢。

1 个答案:

答案 0 :(得分:3)

尝试form_for [:admin, @currency]