我在运行应用程序时遇到此错误:
<ActiveRecord::Associations::CollectionProxy []>
我可以存储报告但无法存储图标。它在Rails 3.2.13中存储得很好,但在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
我可以存储报告,但不存储图标。请帮忙
答案 0 :(得分:1)
我认为您可能错过了强参数中的图标属性。