Monday, 15 February 2010

Rails 4: nested attributes not saving -



Rails 4: nested attributes not saving -

i have stupid problem, can't figured out cause of it. nested attributes of model not saving

poll.rb

class poll < activerecord::base has_many :poll_options accepts_nested_attributes_for :poll_options validates :name, presence: true end

poll_option.rb

class polloption < activerecord::base belongs_to :poll validates :name, presence: true end

polls_controller

def new @poll = poll.new @poll.poll_options.build end def create @poll = poll.create(poll_params) if @poll.save redirect_to poll_path(@poll) else render 'new' end end private def poll_params params.require(:poll).permit(:name, :description, poll_options_attributes: [:id, :name]) end

view

= simple_form_for @poll |poll| = poll.input :name = poll.input :description = simple_fields_for :poll_options |option| = option.input :name = poll.button :submit

what did miss? thanks

it should poll.simple_fields_for, not simple_fields_for.

ruby-on-rails ruby-on-rails-4

No comments:

Post a Comment