简体   繁体   中英

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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