2014-01-20 47 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 %> 

我發現這種方法要簡單得多。