0

Rails 4.0.1, and I really don't understand what I am doing wrong here. I have a model ChallengeList and a model Challenge. ChallengeList has many Challenges:

#ChallengeList
has_many :challenges, :dependent => :destroy
accepts_nested_attributes_for :challenges

I want to make a nested form that allows the user to update challenges while editing a list (code in HAML, but should make sense):

= form_for @challenge_list do |f|
  .field
    = f.label :title, "Title (optional)"
    %br/
    = f.text_field :title
  -# etc, fields for challenge list

  ="#{@challenge_list.challenges.length} challenges"
  -f.fields_for :challenges do |builder|
    .field
      = builder.text_field :description
      %br/
  .actions
    = f.submit 'Save'

But when I try out my form, the field_for section doesn't show anything, even if @challenge_list contains more than 1 challenge. (e.g. challenge_list.challenges.length turns up a number >0).

Am I missing something?

1 Answer 1

1

You forgot an equals sign for fields_for:

  = "#{@challenge_list.challenges.length} challenges"
  = f.fields_for :challenges do |builder|
    .field
      = builder.text_field :description
      %br/
  .actions
    = f.submit 'Save'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.