0

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?

Vincent
  • 1,454
  • 2
  • 17
  • 24

2 Answers2

0

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

  <% unless current_user ...  %>
Miotsu
  • 1,776
  • 18
  • 30
0

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]

usha
  • 28,973
  • 5
  • 72
  • 93