0
我正在爲我的建築物中的網絡製作地圖。我有單獨的樓層模型工作,當你點擊顯示方法時列出每個開關。然後,我想擁有它,以便您可以單擊每個交換機以查看每個交換機端口上的插孔編號。由於我提出了另一個問題,我對交換機的工作有了一些看法,但現在我仍然試圖在同一節目中顯示插孔。下面是我部分的接口(應用程序/視圖/插孔/ _jacks.html.erb):Ruby on Rails爲第三個模型形成路徑
<%= form_for <WhatDoIPutHere?> do |f| %>
<div class="field">
<%= f.label :number %><br />
<%= f.text_field :number %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
現在我知道我需要運行一個耙途徑找出路。 這裏是我耙路線的結果是:
floor_switch_jacks GET /floors/:floor_id/switches/:switch_id/jacks(.:format) jacks#index
POST /floors/:floor_id/switches/:switch_id/jacks(.:format) jacks#create
new_floor_switch_jack GET /floors/:floor_id/switches/:switch_id/jacks/new(.:format) jacks#new
edit_floor_switch_jack GET /floors/:floor_id/switches/:switch_id/jacks/:id/edit(.:format) jacks#edit
floor_switch_jack GET /floors/:floor_id/switches/:switch_id/jacks/:id(.:format) jacks#show
PUT /floors/:floor_id/switches/:switch_id/jacks/:id(.:format) jacks#update
DELETE /floors/:floor_id/switches/:switch_id/jacks/:id(.:format) jacks#destroy
floor_switches GET /floors/:floor_id/switches(.:format) switches#index
POST /floors/:floor_id/switches(.:format) switches#create
new_floor_switch GET /floors/:floor_id/switches/new(.:format) switches#new
edit_floor_switch GET /floors/:floor_id/switches/:id/edit(.:format) switches#edit
floor_switch GET /floors/:floor_id/switches/:id(.:format) switches#show
PUT /floors/:floor_id/switches/:id(.:format) switches#update
DELETE /floors/:floor_id/switches/:id(.:format) switches#destroy
floors GET /floors(.:format) floors#index
POST /floors(.:format) floors#create
new_floor GET /floors/new(.:format) floors#new
edit_floor GET /floors/:id/edit(.:format) floors#edit
floor GET /floors/:id(.:format) floors#show
PUT /floors/:id(.:format) floors#update
DELETE /floors/:id(.:format) floors#destroy
home_index GET /home/index(.:format) home#index
root / home#index
我的問題是我怎麼讀耙路線以查找的form_for行的正確語法?我有同樣的問題讓我的開關視圖在第一時間工作。如果這是一個簡單的問題,並有一個指導,那麼請隨時發送給我。我似乎無法找到一個具體到這個。
在此先感謝您的幫助!
編輯:
class JacksController < ApplicationController
def create
@switch = Switch.find(params[:switch_id])
@jack = @switch.jacks.create(params[:jack])
redirect_to switch_path(@switch)
end
def destroy
@switch = Switch.find(params[:switch_id])
@jack = @switch.jacks.find(params[:id])
@jack.destroy
redirect_to switch_path(@switch)
end
end
這似乎工作,但現在當我嘗試創建一個新的插孔(當我從交換機視圖中點擊提交按鈕時)它節省了地板,並且不用插孔做任何事情。這可以在我的插孔控制器?我將包括我的新代碼和我的插孔控制器。 –
你需要確保你的模型'accep_nested_attributes_for'適當的子模型 – Ron
哦,對不起,在模型本身,而不是視圖。我的錯。我會試試看。 –