有没有人能够使用强参数在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中的关系所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)