I have a database of sports teams that I am displaying in tables/standings. The relevant code involves two models, Tableposition and Draw, which are associated in a has_one relationship. The following static named scope declaration works perfectly:
class Tableposition < ActiveRecord::Base
belongs_to :draw
named_scope :grouptable, :include => :draw, :conditions => ['draws.group = ?', "B"]
end
However, when I try to make it dynamic:
class Tableposition < ActiveRecord::Base
belongs_to :draw
named_scope :grouptable, :include => :draw,
lambda { |group| { :conditions => ['draws.group = ?', group] } }
end
I get the following error:
SyntaxError: /.../app/models/tableposition.rb:4: syntax error, unexpected '\n', expecting tASSOC
I've scoured the web for solutions and have tried converting the curly braces to a do ... end with brackets to no avail. Any thoughts would be hugely appreciated.