2011-02-06 9 views
1

중첩 된 양식을 만들려고하지만 오류가 계속 발생하여 누락되었습니다. 내가이 일을해야 발견 한 일부 온라인 가이드에 따르면 --show 구성보기중첩 된 속성이 작동하지 않음

<%= form_for @config do |f| %> 
    <%= f.fields_for :configoptions do |fp| %> 
    <p> 
     <%= fp.label :name %> 
     <%= fp.text_field :name %> 
    </p> 
    <% end %>  
    <%= f.submit %> 
<% end %> 

--configuration 모델

class Configuration < ActiveRecord::Base 
    has_many :configoptions 
    accepts_nested_attributes_for :configoptions 
end 

. 계속 오류가 발생합니다.

undefined method `configuration_path' for #<#<Class:0x2549dac>:0x2548f88> 

누구나이 작업을 수행 할 수있는 방법을 알고 있습니까?

고맙습니다.

답변

2

경로가 잘못 구성되어있는 것 같습니다. 다음 줄은

<%= form_for @config do |f| %> 

으로 새/업데이트 된 개체를 게시 할 양식 태그를 만듭니다. 이 경우 새 오브젝트 양식의 기본 경로로 configuration_path을 찾습니다. 이

configurations GET /configurations(.:format)   {:action=>"index", :controller=>"configurations"} 
       POST /configurations(.:format)   {:action=>"create", :controller=>"configurations"} 

유사한 목록이 있는지 또는 config/routes.rbresources :configurations을 찾아 rake routes를 사용합니다. (그렇지 않은 경우 resource :configurations을 추가하십시오.) 당신이 라우팅 혼란을받을 경우, 해당 레일 가이드를 체크 아웃 :

<%= form_for @config, :url => some_other_path do |f| %> 
+0

: http://guides.rubyonrails.org/routing.html

다른 방법으로,에, 양식 도우미에 :url 인수를 전달하여 조치를 작성하려면 다른 URL을 지정할 수 있습니다 완벽하게 작동합니다! 고마워. – Lievcin

관련 문제