Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Activeadmin Formtastic custom input

I have a simple app, which has three models Assessment, Question and AssessmentQuestion

In Assessment i have the association like,

class Assessment < ActiveRecord::Base
  has_many :assessment_questions, dependent: :destroy
  has_many :questions, through: :assessment_questions
end

In Question i have,

class Question < ActiveRecord::Base
  has_many :assessment_questions, dependent: :destroy
  has_many :bank_questions, dependent: :destroy
end

In AssessmentQuestion i have,

class AssessmentQuestion < ActiveRecord::Base
  belongs_to :question
  belongs_to :assessment
end

assessment_questions table has :assessment_id, :question_id and :mark columns

I have admin interface using ActiveAdmin gem.

While creating assessments in admin interface, In admin/assessment.rb i have a form generated by the formtastic gem,

  form do |f|
    f.inputs do
      f.input :name
      f.input :duration
      f.input :questions, as: :check_boxes, member_label: :id
      f.input :creator_id
    end

    f.actions :commit
  end

Screen shot of that page

This looks fine and no problem. The thing that i want is while choosing questions through the checkboxes, i want a textbox below or side to each checkbox containing mark of the questions will be filled in text boxes respectively ( through question.assessment_question.mark association ), so that i can edit the prefilled marks of the questions while creating assessment or leave it as it is.

I have tried, but got some error like

undefined method `to_sym' for {:for=>:questions}:Hash

My code,

form do |f|
        f.inputs do
          f.input :name
          f.input :duration
          f.input for: :questions do | question |
            f.input :question, as: :select
            f.input question.assessment_question.mark
           end 
          f.input :creator_id
        end

        f.actions :commit
      end

Any solutions?

like image 654
Kanmaniselvan Avatar asked Oct 23 '14 06:10

Kanmaniselvan


Video Answer


1 Answers

Finally, i figured it out.

I actually created a custom semantic_form_for form _form.html.erb as a partial and included this in admin/assessment.rb file

form partial: 'assessment/form'

That's how i solved.

Reference: http://activeadmin.info/docs/5-forms.html

like image 190
Kanmaniselvan Avatar answered Oct 16 '22 13:10

Kanmaniselvan