Rails:奇异的资源更新路径问题

时间:2012-10-02 08:35:34

标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.2 rails-routing form-for

我正在努力获取正确的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|

生成更新的错误网址(但适用于创建):

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

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

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

所以我的问题是:执行此操作的正确方法是什么,因此我放置的url用于创建和更新操作?

1 个答案:

答案 0 :(得分:0)

问题在于语言环境,而不在于单一资源。尝试使用

生成网址
quickwizard_business_path(@business, locale: nil)