2

나는 지금 내 폼이레일에서 중첩 된 formtastic 모델이 한 필드를 건너 뛰고 있습니까?

_form.html.erb

<%= semantic_form_for @tournament do |f| %> 
<%= f.inputs do %> 
    <%= f.input :name, :hint => "What is the name of the Tournament?" %> 
<%= f.semantic_fields_for :courts do |builder| %> 
     <%= render :partial => "court_fields", :locals => { :f => builder } %> 
    <% end %> 

_court_fields.html.erb

<div class="nested_fields"> 
<%= f.input :name, :input_html => {:class => "name"} %> 
<%= f.semantic_fields_for :ages do |builder| %> 
    <%= render :partial => "age_fields", :locals => { :f => builder } %> 
<% end %> 

_age_fields 같이이 구조를 모델

class Tournament < ActiveRecord::Base 
    AGES = ["5u", "6u", "7u", "8u"] 
    has_many :courts, :dependent => :destroy 
    accepts_nested_attributes_for :courts, :reject_if => lambda { |a| a[:name].blank? }, :allow_destroy => true 

class Court < ActiveRecord::Base 
    belongs_to :tournament, :autosave => true 
    has_many :ages, :dependent => :destroy 
    accepts_nested_attributes_for :ages, :reject_if => lambda { |a| a[:name].blank? }, :allow_destroy => true 

class Age < ActiveRecord::Base 
    belongs_to :court 

있습니다. html.erb

Testing ...am I getting in here 
<%= f.input :name, :as => :check_boxes, :collection => Tournament::AGES, :input_html => {:class => "age_limits"} %> 

모든 것이 ages_fields에 표시 아무것도를 제외하고 잘 작동하는 것 같다 부분 ...없는 문제

+0

_court_fields.html.erb에서 부분적인 이름은 age_fields이고 부분은 _ages_fields.html.erb입니다 (연령대는 s입니다). 그것을 바꾸어보십시오. – scumah

+0

그 오타되었습니다 ... 부분은 _age_fields.html.erb라는 이름입니다 – Trace

+0

잘 잡았지만 부분은 정확하게 – Trace

답변

3
의 원인이 될 수있는 것을 Testing ...am I getting in here이 표시되지 않은 체크 박스와 심지어 더미 텍스트 .... 어떤 아이디어

제가 생각할 수있는 분명한 이유는 Courtages이 있습니까?

[편집] Court에 관계가 있다는 것이 실제로 분명했습니다. 코드가 이미 존재하는 경우 court에 대해서만 age이 표시됩니다.

의견에 나온 내용은 ​​법원에 실제 나이가 없으므로 연령이 표시되지 않습니다.

당신은 당신의 컨트롤러에서이 작업을 수행하는 경우 :

def new 
    @tournament = Tournament.new 
    @tournament.courts.build 
    @tournament.courts[0].ages.build 
end 

이것은 당신이 하나 이상의 (빈) 코트 하나 (빈) 연령이 있는지 확인합니다.

그렇지 않으면 cocoon과 같은 보석을 사용하여 필요할 경우 새로운 요소를 동적으로 추가하는 것도 고려해 볼 수 있습니다.

희망이 도움이됩니다.

+0

라는 이름입니다. 내가 가지고있는 모델을 본다면 .... 여기에 내 레일 콘솔 출력이 있습니다. = Court.first => # <코트 id : 4, name : "대회 [courtts_attributes [1] [name]", 주소 : "대회 [courtts_attributes [1] [주소]", 도시 : "토너먼트 – Trace

+0

c. 연령대 (0.3ms) 나이 들었을 때 (0.3ms) '연령대'부터 '연령대''코트트 _ 아이디 '= 4 => [] – Trace

+0

내가 그랬던 것처럼 법원에 실제 나이가 없으므로 아무도 없다. 그에 따라 대답을 편집했습니다. – nathanvda