首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >#<ActiveRecord::Associations::CollectionProxy []> Rails

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

Stack Overflow用户
提问于 2016-07-18 16:09:52
回答 1查看 279关注 0票数 0

我在运行我的应用程序时遇到了这个错误:

<ActiveRecord::Associations::CollectionProxy []>

我可以存储报告,但不能存储图标。它在Rails 3.2.13中存储得很好,但在Rails 4.2.6中提出了这个问题。

report.rb:

代码语言:javascript
复制
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:

代码语言:javascript
复制
class Icon < ActiveRecord::Base
  belongs_to :report
end

reports_controller:

代码语言:javascript
复制
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

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-07-20 07:48:27

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38441436

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档