Radio Buttons with simple_form nested

Asked

Viewed 44 times

1

I need to set up a input radio in a simple form with association.

I’m following the documentation, but the difficulty is being in rendering the radio in the right way. Instead of presenting the content of the association it presents a array of YES and IN THE for each record.

My models:

class Page < ActiveRecord::Base
  has_many :questions
end

class Question < ActiveRecord::Base
  has_many :answer_options
  belongs_to :page
end

class AnswerOption < ActiveRecord::Base
  belongs_to :question
end

My code is like this:

- @page.questions.each do |question|
  h1 = question.title
  h5 = question.description

  = simple_form_for question do |f|
    = f.error_notification

    .form-inputs
      = f.simple_fields_for :answer_options do |ff|
        = ff.input :content, label: false, as: :radio_buttons

    .form-actions
      = f.button :submit, class: 'btn btn-success'

Funny thing is, if I leave the field without the as: :radio_buttons it brings the content right but in input text format, when actually I need to present in format radio.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.