I have a problem, I got a 'User' model and a 'Professional' model. Inside the Professional model, it is specified that it belongs to a user.
However, there is no written relation in the user model. There is nothing wrong it should be like that, a user can have a professional (thanks to the belongs_to), but not always.
Here is the problem: I can't do "User.find(49).professional" to test if the user n°49 is a professional (it should return a boolean).
However I can do "Professional.find(65).user", it returns true if the the professional n°65 is a user and false if he is not.
In some User view, I have this that doesn't work because of that:
- if @user.professional?
div class="page-header"
h1 Professional info
ul style="list-style: none"
// Id
li
strong
= model_class.human_attribute_name(:id)
' :
= @user.professional.id
// Country
li
strong
= model_class.human_attribute_name(:country)
' :
= @user.professional.country
[...]
I got a wide "li" list. So, the if condition doesn't work, and the @user.professional.someprofessionalattributes doesn't work too.
What I first thought was that I should write in the User model "has_none_or_one", but it doesn't exist when I looked at the official docs.
Thanks for your help