Reputation: 1621
I have the following method in a class and I need to pull an item from another model to use in this method. I cant seem to pull the item because I am using current_user to get the other item and the model does not recognize current_user. I am not sure how DRY this is anyway because I have read that the model should not call current_user. Here is the method...
class Upsell
include Mongoid::Document
belongs_to :user
belongs_to :charges
...
def total_fees
items = []
items << (current_user.reportapprovals.first.admin_request_report_type).to_i
if self.multiple_admin == true
items << self.multiple_admin_amount
end
end
My error is that
undefined local variable or method `current_tenant' for #<Upsell:0xc82c9d39>
I am wondering if I should set user in the model but so far that has not worked.
@user = User.find(params[:id])
Upvotes: 1
Views: 73
Reputation: 6100
You need to pass current_user
as function parameter
def total_fees_for user
items = []
items << (user.reportapprovals.first.admin_request_report_type).to_i
if self.multiple_admin == true
items << self.multiple_admin_amount
end
end
Upvotes: 3