Question

For testing purposes, I want to make a particular part of a layout only visible to ONE particular user, using Devise for authentication. Here is what I want in psuedo ERB:

<% unless PARTICULARUSER.present? %>
        <%= render "PARTIAL FOR EVERYONE" %>  
      <% else %>
        <%= render :partial => "PARTIAL FOR THE SPECIAL USER" rescue render :partial => 
            'PARTIAL FOR EVERYONE' %>

Is there a proper way to do this?

Was it helpful?

Solution

You're doing it right. If you're using Devise, you have the current_user helper, so:

  <% unless current_user ...  %>

OTHER TIPS

I think you would want to do something like this

<% unless current_user == particularuser %>
    <%= render "PARTIAL FOR EVERYONE" %>  
<% else %>
    <%= render :partial => "PARTIAL FOR THE SPECIAL USER" rescue render :partial => 
       'PARTIAL FOR EVERYONE' %>

If you are not using devise, the logged in user is available in session. session[:user]

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top