ruby-on-rails – 在rails_admin中使用orderable获取has_many:通过rails 4中的关系

ruby-on-rails – 在rails_admin中使用orderable获取has_many:通过rails 4中的关系,第1张

概述我正在尝试弄清楚如何在 https://github.com/sferik/rails_admin/wiki/Has-many-%3Athrough-association的示例中给出如何使用位置排序,但不使用受保护的属性,而是使用Rails 4的强参数.如果我尝试使用没有attr_accessible:block_ids的页面上给出的block_ids =函数,我会收到一条带有未知属性的Acti 我正在尝试弄清楚如何在 @L_301_0@的示例中给出如何使用位置排序,但不使用受保护的属性,而是使用Rails 4的强参数.如果我尝试使用没有attr_accessible:block_IDs的页面上给出的block_IDs =函数,我会收到一条带有未知属性的ActiveRecord :: UnkNownAttributeError错误:block_IDs.显然,如果我使用attr_accessible:block_IDs,它会要求我将protected_attributes添加到我的Gemfile中,这不是Rails 4方式.

有没有人能够使用强参数在rails_admin中为Rails 4制作可订购位置?

解决方法 省略attr_accessible:block_IDs并在底部应用替代解决方案对我有用.

PS:Rails 4.2.0,rails_admin为0.6.6

class GrID < ActiveRecord::Base  has_many :block_grID_associations,:dependent => :delete_all,:autosave => true,:include => :block  has_many :blocks,:through => :block_grID_associations  def block_IDs=(IDs)    unless (IDs = IDs.map(&:to_i).select { |i| i>0 }) == (current_IDs = block_grID_associations.map(&:block_ID))      (current_IDs - IDs).each { |ID| block_grID_associations.select{|b|b.block_ID == ID}.first.mark_for_destruction }      IDs.each_with_index do |ID,index|        if current_IDs.include? (ID)          block_grID_associations.select { |b| b.block_ID == ID }.first.position = (index+1)        else          block_grID_associations.build({:block_ID => ID,:position => (index+1)})        end      end    end  end  rails_admin do    configure :block_grID_associations do      visible(false)    end    configure :blocks do      orderable(true) # only for multiselect Widget currently. Will add the possibility to order blocks      # configuration here    end  endend
总结

以上是内存溢出为你收集整理的ruby-on-rails – 在rails_admin中使用orderable获取has_many:通过rails 4中的关系全部内容,希望文章能够帮你解决ruby-on-rails – 在rails_admin中使用orderable获取has_many:通过rails 4中的关系所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1275687.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-09
下一篇 2022-06-09

发表评论

登录后才能评论

评论列表(0条)

保存