0
感謝大家以前的幫助。我會假設這將是一個相當不錯的問題,但是我有一個問題,而且我似乎無法弄清楚。ROR子 - 子資源形式故障
基本上, 我正在跟蹤幾個醫院的防火牆及其區域/接口。所以我的模型看起來像
Hospital
|--> Firewall
|--> fwzones
我已經幾乎得到了一切,除了新的形式。
,這裏是我的routes.rb
mine::Application.routes.draw do
resources :hospitals do
resources :firewalls do
resources :fwzones
end
end
end
hospital.rb
class Hospital < ActiveRecord::Base
has_many :firewalls, :dependent => :destroy
end
firewall.rb
class Firewall < ActiveRecord::Base
belongs_to :hospital
has_many :fwzones
end
fwzone.rb
class Fwzone < ActiveRecord::Base
belongs_to :firewall
end
fwzone位指示
class FwzonesController < ApplicationController
....
def new
@hospital = Hospital.find(params[:hospital_id])
@firewall = @hospital.firewalls.find(params[:firewall_id])
@fwzone = @firewall.fwzones.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @fwzone }
end
end
....
end
,我已經試過
<%= form_for([@hospital,@hospital.firewalls.fwzones.build]) do |f| %>
Error: undefined method `fwzones' for #<Class:0x1bba030>
-------------------
<%= form_for([@firewall,@firewalls.fwzones.build]) do |f| %>
<%= form_for([@hospital,@firewalls.fwzones.build]) do |f| %>
Error: undefined method `fwzones' for nil:NilClass
-------------------
<%= form_for([@hospital.firewalls,@fwzones]) do |f| %>
Error: undefined method `model_name' for NilClass:Class
我認爲它有事情做與醫院或防火牆模式,但我真的無法弄清楚形式的字符串。任何幫助表示讚賞。哦,這是我的耙路線,而我們在這裏。
hospital_firewall_fwzones GET /hospitals/:hospital_id/firewalls/:firewall_id/fwzones(.:format) {:action=>"index", :controller=>"fwzones"}
hospital_firewall_fwzones POST /hospitals/:hospital_id/firewalls/:firewall_id/fwzones(.:format) {:action=>"create", :controller=>"fwzones"}
new_hospital_firewall_fwzone GET /hospitals/:hospital_id/firewalls/:firewall_id/fwzones/new(.:format) {:action=>"new", :controller=>"fwzones"}
edit_hospital_firewall_fwzone GET /hospitals/:hospital_id/firewalls/:firewall_id/fwzones/:id/edit(.:format) {:action=>"edit", :controller=>"fwzones"}
hospital_firewall_fwzone GET /hospitals/:hospital_id/firewalls/:firewall_id/fwzones/:id(.:format) {:action=>"show", :controller=>"fwzones"}
hospital_firewall_fwzone PUT /hospitals/:hospital_id/firewalls/:firewall_id/fwzones/:id(.:format) {:action=>"update", :controller=>"fwzones"}
hospital_firewall_fwzone DELETE /hospitals/:hospital_id/firewalls/:firewall_id/fwzones/:id(.:format) {:action=>"destroy", :controller=>"fwzones"}
hospital_firewalls GET /hospitals/:hospital_id/firewalls(.:format) {:action=>"index", :controller=>"firewalls"}
hospital_firewalls POST /hospitals/:hospital_id/firewalls(.:format) {:action=>"create", :controller=>"firewalls"}
new_hospital_firewall GET /hospitals/:hospital_id/firewalls/new(.:format) {:action=>"new", :controller=>"firewalls"}
edit_hospital_firewall GET /hospitals/:hospital_id/firewalls/:id/edit(.:format) {:action=>"edit", :controller=>"firewalls"}
hospital_firewall GET /hospitals/:hospital_id/firewalls/:id(.:format) {:action=>"show", :controller=>"firewalls"}
hospital_firewall PUT /hospitals/:hospital_id/firewalls/:id(.:format) {:action=>"update", :controller=>"firewalls"}
hospital_firewall DELETE /hospitals/:hospital_id/firewalls/:id(.:format) {:action=>"destroy", :controller=>"firewalls"}
hospitals GET /hospitals(.:format) {:action=>"index", :controller=>"hospitals"}
hospitals POST /hospitals(.:format) {:action=>"create", :controller=>"hospitals"}
new_hospital GET /hospitals/new(.:format) {:action=>"new", :controller=>"hospitals"}
edit_hospital GET /hospitals/:id/edit(.:format) {:action=>"edit", :controller=>"hospitals"}
hospital GET /hospitals/:id(.:format) {:action=>"show", :controller=>"hospitals"}
hospital PUT /hospitals/:id(.:format) {:action=>"update", :controller=>"hospitals"}
hospital DELETE /hospitals/:id(.:format) {:action=>"destroy", :controller=>"hospitals"}
Thanks Mark。實際上我有兩本紅寶石書,但他們並沒有談論很多關於軌道的問題,這真的很煩人。 –
這解決了眼前的問題,但現在它說,示範醫院不響應任何方法的名稱 –