ruby-on-railsrubyhelpermethods

User Helper Method - grabbing users whose ID doesn't match current user ID


trying to write a helper method with 3 basic conditions. adding the 3rd one, which is trying to take the current user out of the results, is resulting in an error.

  def male_soccer_players
    return User.where(:gender => "male", :soccer => true, :id != current_user.id)
  end

The error is

app/controllers/application_controller.rb:12: syntax error, unexpected ')', expecting => 

Solution

  • Problem in this :id != current_user.id Rails .where pass only hash try

    def male_soccer_players
      User.where(:gender => "male", :soccer => true).where('id != ?', current_user.id)
    end
    

    or

    def male_soccer_players
      User.where('gender = ? and soccer = ? and id != ?', "male", true, current_user.id)
    end