Here is the method described in the Rails API :
scope(name, body, &block)
This is an example of using this method, also described in the Rails API:
class Shirt < ActiveRecord::Base
scope :red, -> { where(color: 'red') } do
def dom_id
'red_shirts'
end
end
end
Question about the following code:
do
def dom_id
'red_shirts'
end
end
What does it mean? I can't find any Ruby syntax about a block that could follow a lambda. Did I miss something? Thanks for any help.
source
share