shubham
shubham

Reputation: 39

Rails current_user use in model

I am making an application where each user has access to multiple properties and can set assumptions for each property they have access to for modelling cashflows.

So user 1 has access to property 1 and sets assumptions that rent is 10k. user 2 has access to property 1 and sets assumptions that rent is 20k. Now if User 1 wants to calculate the NPV of rents over next 10 years then I need to use 10k and if user 2 wants NPV then need to use 20k.

I was thinking of implementing NPV of rent in Property Model, however then it will require current_user. Any other solution?

Upvotes: 0

Views: 254

Answers (1)

steel
steel

Reputation: 12520

I would pass current_user to the model method, when you call it in the controller. That's a common technique.

# controller
def action
  Model.calculate_npv(current_user)
end

Upvotes: 2

Related Questions