【发布时间】:2016-07-20 15:48:27
【问题描述】:
我在运行我的应用程序时遇到了这个错误:
<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
报告控制器:
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
我可以存储报告,但未存储图标。请帮忙
【问题讨论】:
-
将此行
if @report.save更改为if @report.save!时的错误消息是什么? -
抱歉,但这不是错误。您能否提供来自您的日志的完整堆栈跟踪以及与中断行匹配的代码?
标签: ruby-on-rails activerecord