In the following example, how can the amount_below_limit instance method access the argument to the max_weight scope?
# Model
class Elephant < ActiveRecord::Base
scope :max_weight, lambda { |limit| where('weight <= ?', limit) }
def amount_below_limit
max_weight = # How can I see 1000 from here?
max_weight - weight
end
end
# Controller
@elephants = Elephant.max_weight(1000)
# View
<% @elephants.each do |elephant| %>
<%= elephant.amount_below_limit %>
<% end %>
Thanks for your suggestions.
In the end, I refactored my code to make the parameter to
max_weightan instance variable, which I then passed on to theamount_below_weightmethod.