我在运行我的应用程序时遇到了这个错误:
<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
endicon.rb:
class Icon < ActiveRecord::Base
belongs_to :report
endreports_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我可以存储报告,但图标没有存储。请帮帮忙
发布于 2016-07-20 07:48:27
我认为您可能忽略了强参数中的图标属性。
https://stackoverflow.com/questions/38441436
复制相似问题