1

I use gem 'nested_form' in rails 3.2

Models:

meeting_agenda.rb:

class MeetingAgenda < ActiveRecord::Base
  has_many :meeting_questions, :inverse_of => :meeting_agenda
  accepts_nested_attributes_for :meeting_questions, allow_destroy: true
  attr_accessible :meeting_questions_attributes
end

meeting_question.rb:

class MeetingQuestion < ActiveRecord::Base
  has_one :meeting_answer, :inverse_of => :meeting_question
  accepts_nested_attributes_for :meeting_answer
  attr_accessible :meeting_answer_attributes
end

meeting_answer.rb

class MeetingAnswer < ActiveRecord::Base
  belongs_to :meeting_question
end

Controller:

class MeetingProtocolsController < ApplicationController

  def new
    @agenda = MeetingAgenda.new
  rescue => error
    render_403
  end


  def create
    @agenda = MeetingAgenda.new(params[:meeting_agenda])

    if @agenda.save && protocol.save
      flash[:notice] = l(:notice_successful_create)
      redirect_to action: 'show', id: @agenda.id
    else
      render action: 'new'
    end
end

View:

new.html.haml:

= nested_form_for @agenda do |f|
# ...

  = f.fields_for :meeting_questions do |question|
    # ...

    # Fields for answer is not showing!
    = question.fields_for :meeting_answer do |answer| # <-- blank

      %p # <-- blank
        = answer.label :reporter_id_is_contact, t(:label_meeting_question_user_is_contact) # <-- blank
        = answer.check_box :reporter_id_is_contact; # <-- blank

        = question.link_to_remove l(:button_delete) # <-- blank

  = f.link_to_add l(:button_add), :meeting_questions
  = submit_tag l(:button_create)

has_one relation with accepts_nested_attributes_for is empty.

Same form working great on rails 5.

0

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.