简体   繁体   English

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

[英]#<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. 它在Rails 3.2.13中存储良好,但是在Rails 4.2.6中提出了这个问题。

report.rb: 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: icon.rb:

class Icon < ActiveRecord::Base
  belongs_to :report
end

reports_controller: 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

I am able to store reports but icons are not stored. 我可以存储报告,但不存储图标。 Please help 请帮忙

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

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

相关问题 ActiveRecord :: Associations :: CollectionProxy上的Rails方法 - Rails method on ActiveRecord::Associations::CollectionProxy Rails 3 HABTM产生ActiveRecord :: Associations :: CollectionProxy对象 - Rails 3 HABTM yields ActiveRecord::Associations::CollectionProxy objects 在Capybara中伪装ActiveRecord :: Associations :: CollectionProxy与Mocha(Rails) - Faking ActiveRecord::Associations::CollectionProxy with Mocha in Capybara (Rails) Rails“ActiveRecord_Associations_CollectionProxy的未定义方法” - Rails “undefined method for ActiveRecord_Associations_CollectionProxy” ActiveRecord_Associations_CollectionProxy的未定义方法[rails] - undefined method for ActiveRecord_Associations_CollectionProxy [rails] Rails循环通过ActiveRecord :: Associations:CollectionProxy - Rails loop through ActiveRecord::Associations:CollectionProxy 表导轨中ActiveRecord :: Associations :: CollectionProxy的排序顺序 - Sort order for ActiveRecord::Associations::CollectionProxy in table rails 什么是 <ActiveRecord::Associations::CollectionProxy []> ? - What is <ActiveRecord::Associations::CollectionProxy []>? ActiveRecord :: Associations :: CollectionProxy - ActiveRecord::Associations::CollectionProxy Rails,ActiveRecord_Associations_CollectionProxy调用ActiveRecord方法的方式 - Rails, The way for ActiveRecord_Associations_CollectionProxy to call method of ActiveRecord
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM