繁体   English   中英

# <ActiveRecord::Associations::CollectionProxy []> 在Rails中

[英]#<ActiveRecord::Associations::CollectionProxy []> in Rails

我在运行应用程序时遇到此错误:

<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

report_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

我可以存储报告,但不存储图标。 请帮忙

我认为您可能错过了强参数中的图标属性。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM