Search code examples
ruby-on-railsaction-filter

RoR filter on controller as this SQL


How to write filter on the controller in Ruby on Rails, that is eqvivalent to this SQL code

select * from persons where persons.category = 'developers'

Solution

  • Use this:

    before_filter :nerds_only
    
    private
    
    def nerds_only
      @people = Person.where(:category => 'developers')
    end