Reputation: 1
In total there are two types of models: one is called business, another is user, inside user I also have an admin boolean attribute. I generated two devise for them. However, when I use
<% if business.signed_in? %>
<%= hidden_field_tag 'business', current_business.company_name %>
<% elsif user.signed_in? %>
<% if current_user.admin? %>
<%= hidden_field_tag 'approved', true %>
<% end %>
<% end %>
in a particular view, say this view corresponds to a controller 'object', both business_signed_in?
and user_signed_in?
are not working (No method error). Can anyone help me with how to modify my controller to make the view work? Only the admin and business can access this particular view, but not other users.
Thanks!
Upvotes: 0
Views: 71
Reputation: 6121
Devise user signed_in or not is a redundant/unnecessary check. Anyway you are using the current_user
method later so check that directly, store it in a variable and check whether it is present?
. If signed_in, it will return user object else nil. You can then use this the following way.
<% if (business = current_business).present? %>
<%= hidden_field_tag 'business', business.company_name %>
<% elsif (user = current_user).present? && user.admin? %>
<%= hidden_field_tag 'approved', true %>
<% end %>
Upvotes: 1