Reputation: 150
I want to show the user a part of the page if he has an attribute with a certain value.
something like this
<% if user.st == "Completed" %>
<p>just for him</p>
<% end %>
I get undefined method for nil class, how can I select the class in my views directly so I can access the attribute. I cannot use any params
edit: If I do this it works, but I want to check the attribute not if he is signed in
<% if user_signed_in? %>
<% end %>
thanks
Upvotes: 1
Views: 343
Reputation: 17834
In place of user
use current_user
, I'm assuming that it is for signed in user only
<% if current_user.st == "Completed" %>
<p>just for him</p>
<% end %>
Upvotes: 2
Reputation: 4053
You can do something like this:
In your controller:
@user = User.find(params[:id]) #or whatever user you want
In your view:
<% if @user.st == "Completed" %>
<p>just for him</p>
<% end %>
Upvotes: 0