0

我正在努力获取正确的 URL 以提供给 form_for 以更新操作以处理单个资源。

我的 routes.rb 如下:

scope "(:locale)", :locale => /en|fr/ do
  namespace :quickwizard, :module => 'quick_wizard' do
    resource :business, controller: 'business'
  end
end

给出以下路线:

     quickwizard_business POST   (/:locale)/quickwizard/business(.:format)          quick_wizard/business#create {:locale=>/en|fr/}
 new_quickwizard_business GET    (/:locale)/quickwizard/business/new(.:format)      quick_wizard/business#new {:locale=>/en|fr/}
edit_quickwizard_business GET    (/:locale)/quickwizard/business/edit(.:format)     quick_wizard/business#edit {:locale=>/en|fr/}
                          GET    (/:locale)/quickwizard/business(.:format)          quick_wizard/business#show {:locale=>/en|fr/}
                          PUT    (/:locale)/quickwizard/business(.:format)          quick_wizard/business#update {:locale=>/en|fr/}
                          DELETE (/:locale)/quickwizard/business(.:format)          quick_wizard/business#destroy {:locale=>/en|fr/}

在视图中:

= simple_form_for @business, url: quickwizard_business_path(@business), validate: true do |f|

生成不正确的更新 url(但适用于创建):

<form accept-charset="UTF-8" action="/15/quickwizard/business" ...

如果我手动输入正确的路线,它适用于更新:

= simple_form_for @business, url:"/quickwizard/business", html: { method: 'put' }, validate: true do |f|

所以我的问题是:这样做的正确方法是什么,以便我放置的 url 同时适用于创建和更新操作?

4

1 回答 1

0

问题在于语言环境,而不是单一资源。尝试生成 url

quickwizard_business_path(@business, locale: nil)
于 2012-10-02T08:42:23.417 回答