Search code examples
ruby-on-railsactivescaffold

Displaying links on columns mapped to custom attributes


Say I have Course that has_many Students. I also have def top_student in the Course class. I now have an active_scaffold on top of Course, but if I add top_student as a column it show shows #, but no link. I'd like a link to the Student who is the Top Student. Any way to make this happen?


Solution

  • class Course < ActiveRecord::Base
      # Class method
      def self.top_student
        # Some logic
      end
    end
    

    it should be:

    <%=link_to "Top Student", Course.top_student %>