Ruby on Rails
Monday, February 18, 2013
Hi
I have a model, let's call it entry, that belongs to a user. The user and the entry also belongs to a company.
Can I add a condition on the belongs_to relations to check this?
Something like:
belongs_to :assigned_user, class_name: "User" , conditions: { company_id: company_id }
This doesn't work because company is set on the Entry in the create action, like this:
def create
...
@entry.company = current_user.company
....
And current_user is the Devise helper and not available in the model.
So, can I achieve this somehow?
-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/mq7uEeY0yGAJ.
For more options, visit https://groups.google.com/groups/opt_out.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment