2014-01-20 49 views
0

我有浅嵌套资源路线如下图所示:轨道4条浅航线资源表单提交不工作

resources :venues, shallow: true do 
     #Halls 
     get "hall/:id/exhibition" => "halls#exhibition", as: :exhibition 
     get "hall/:id/visit" => "halls#visit", as: :hall_visit 
     get "structure", :to => "venues#venue_structure" 
     resources :asset_types, :booths_tags, :tags, :uploaded_files, :events, :chats 
     resources :halls do 
      resources :webcasts 
      resources :booths do 
       resources :chats 
      end 
     end 
    end 

下面是当前正在使用的simple_form。

= simple_form_for(hall_booths_path(@booth), :html => { :class => "form-horizontal" }, :wrapper => "horizontal", defaults: { :input_html => { class: "form-control"}, label_html: { class: "col-lg-4" } }) do |f| 
    = f.simple_fields_for @booth do |b| 

的问题是,hall_booths_path(@booth)部分产生的/halls/1/booths/new代替/halls/1/booths

有什么错在这里,需要修复?

booths路线:

hall_booths_path  GET  /halls/:hall_id/booths(.:format) booths#index 
        POST /halls/:hall_id/booths(.:format) booths#create 
new_hall_booth_path GET  /halls/:hall_id/booths/new(.:format) booths#new 
edit_booth_path  GET  /booths/:id/edit(.:format) booths#edit 
booth_path   GET  /booths/:id(.:format) booths#show 
        PATCH /booths/:id(.:format) booths#update 
        PUT  /booths/:id(.:format) booths#update 
        DELETE /booths/:id(.:format) booths#destroy 
+0

你可以在你的应用程序路径中发布“耙路线”的输出? – beck03076

+0

@ beck03076我刚刚更新了我的答案,路线 –

+0

@ beck03076我试过,但得到不同的大厅id是'/ halls/3/booths/new'的同一个网址我仍然得到'/ new' –

回答

1

传入的选项哈希的路径,而不是作为第一个参数:

<%= simple_form_for :booth, :url => hall_booths_path(@hall) do |f| %> 
    ... 
<% end %> 

注意,参数hall_booths_pathHall,而不是一个Booth。当你创建一个孩子时,你需要提供父母。

另一种选择是不传递URL而是传递模型对象。假设@hall是现有Hall@booth是一个新的Booth

<%= simple_form_for [@hall, @booth] do %> 
    ... 
<% end %> 

我发现这种方法要简单得多。