Jump to content

The ultimate community for Ruby on Rails developers.


Photo

Active admin with HABTM associations & nested_attributes in Rails 4?

activeadmin habtm rails4 nested_attributes

  • Please log in to reply
No replies to this topic

#1 Mohd Anas

Mohd Anas

    Passenger

  • Members
  • 1 posts

Posted 18 November 2013 - 09:24 AM

I am using active admin in rails 4 and trying to add new nested attribute through active admin form first time is creating but when i am trying to update it, it is not working. Here are some codes snippets

questionset.rb

class QuestionSet < ActiveRecord::Base
has_and_belongs_to_many :questions

accepts_nested_attributes_for :questions,
allow_destroy: true,
reject_if: lambda { |q| q[:description].blank? or q[:title].blank? }
end

quesiton.rb

class Question < ActiveRecord::Base
include ActionView::Helpers::TextHelper

has_and_belongs_to_many :question_sets

end

And in active admin i am using

form do |f|
f.inputs t('user.details') do
f.input :title
f.input :description
f.inputs do
f.has_many :questions do |p|
p.input :title
p.input :description
p.input :question_type, as: :select, collection: Question::QUESTION_TYPES
p.has_many :question_selections do |q|
q.input :label
q.input :text
end

p.input :obligatory
p.input :is_shown_in_report
p.input :destroy, as: :boolean, required: false, label: t('remove')
end
if params[:id]
f.input :is
finished
end
end
end
f.actions
end

 

 

and it is using strong parameters, here is the code

 

controller do
def permitted_params
params.permit question_set: [:id, :title, :description, :is_finished, :created_by_admin, questions_attributes: [:id, :question_set_id, :user_id, :title, :question_type, :description, :obligatory, :is_shown_in_report, :is_user_question, :destroy, questionselections_attributes: [:id, :label, :text]]]
end
end

 

 

But it is not working as expected.

 

Thanks







Also tagged with one or more of these keywords: activeadmin, habtm, rails4, nested_attributes

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users