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
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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With