代码之家  ›  专栏  ›  技术社区  ›  Notinlist

RoR:清除每个记录的链接

  •  0
  • Notinlist  · 技术社区  · 15 年前

    我在下一段中讲的是半个红宝石半个英语

    我有 Person s和我有宠物。 has_many Pet . 我有一张桌子 手机里有宠物,比如:

    def pets_column(record)
      if record.pets.count == 0
        'no pets'
      else
        record.pets.collect{|p| html_escape(p.to_label) }.join('<br />')
      end
    end
    

    它是正确显示的,并且是一个链接,显示宠物的嵌套表。

    record_frozen_at is not null 然后 宠物 记录列表也必须冻结。(不添加、不删除、不更新这些宠物)

    columns[:pets].clear_link 是否针对整个表而不是每个记录。)

    1 回复  |  直到 15 年前
        1
  •  0
  •   Notinlist    15 年前

    class PetController < ActionController::Base
    
      # ...
    
      protected
    
      def person_mutable?
        person_id = active_scaffold_constraints[:person]
        return false if person_id.nil?
        person = person.find_by_id(person_id)
        return false if person.nil?
        return person.record_frozen_at.nil?
      end
    
      def create_authorized?
        return person_mutable?
      end
    
      def update_authorized?
        return person_mutable?
      end
    
      def delete_authorized?
        return person_mutable?
      end
    end
    
    推荐文章