Reputation: 836
I am facing this error while running my application:
<ActiveRecord::Associations::CollectionProxy []>
I am able to store reports but couldn't store icons. It is storing fine in Rails 3.2.13, but raising this issue in Rails 4.2.6.
report.rb:
class Report < ActiveRecord::Base
belongs_to :user
has_many :icons, -> { order 'position_id ASC'}
accepts_nested_attributes_for :icons, :reject_if => lambda { |a| a[:icon].blank? }, :allow_destroy => true
end
icon.rb:
class Icon < ActiveRecord::Base
belongs_to :report
end
reports_controller:
def new
@report = @user.reports.new({
:background_color => Rails.application.config.custom.accounts.send(@user.account.name).colors.background,
:text_color => Rails.application.config.custom.accounts.send(@user.account.name).colors.commentary,
:button_color => Rails.application.config.custom.accounts.send(@user.account.name).colors.button
})
3.times { @report.icons.build }
end
def create
respond_to do |format|
if @report.save
format.json { render :json => { :success => true, :user_id => @user.id, :report_id => @report.id, :report_title => @report.title, :icon_array => @report.icons, :redirect => user_report_url(current_user, @report.id) } }
else
format.json { render :json => { :success => false } }
end
end
end
I am able to store reports but icons are not stored. Please help
Upvotes: 0
Views: 313
Reputation: 685
I think you might have missed icon attributes in the strong parameters.
Upvotes: 1