Rails form validation is designed to go in the model most easily. But I need to make sure the current user has the required privileges to submit a post and the current_user
variable is only accessible in the controller and view.
I found this answer in a similar question:
You could define a
:user_gold
virtual attribute forBook
, set it in the controller where you have access tocurrent_user
and then incorporate that into yourBook
validation.`
How can I set this up with my post and user controller so that the current_user
variable is accessible in the model?
Solution:
This whole thing is wrong from an application design perspective as @Deefour's answer pointed out. I changed it so my view doesn't render the form unless the condition is true.