Question

really quick i got this error: "syntax error, unexpected tIDENTIFIER, expecting ')'", when im trying to use these code to find a value in a db (im just learning ruby).

  def load_leagues
    @men_leagues = League.where(kind: 'men').order('id ASC').find_all
    @men_active_leagues = League.where(active: true AND kind: 'men').order('id ASC').find_all
    @women_leagues = League.where(kind: 'women').order('id ASC').find_all
    @current_user = current_user
  end

I think that the line of @men_active_leagues is the one giving me troubles.

Thanks for everything!

Was it helpful?

Solution

There is no AND operator in ruby.

To use AND in a where statement you could either specify both the arguments.

@men_active_leagues = League.where(active: true, kind: 'men').order('id ASC').find_all

or you could specify it as a string

@men_active_leagues = League.where("active = TRUE AND kind = 'men'").order('id ASC').find_all

OTHER TIPS

Resolved in following, self-explanatory, hash composition was wrong:

def load_leagues
   @men_leagues = League.where(kind: 'men').order('id ASC').find_all
   @men_active_leagues = League.where({active: true, kind: 'men'}).order('id ASC').find_all
   @women_leagues = League.where(kind: 'women').order('id ASC').find_all
   @current_user = current_user
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top