Sha256: e8e2d85d883ae3f56b493a5497aca57cf050c822a28f4a75e5015ad28186bef8
Contents?: true
Size: 1.86 KB
Versions: 24
Compression:
Stored size: 1.86 KB
Contents
<h1>Pretender</h1> <h4>Log in as another user in Rails</h4> <pre><code>true_user => <%= current_user ? true_user.name : 'NOT SIGNED IN' %></code></pre> <p>Sign in with an <b>Admin</b> user and then impersonate other users</p> <h3>Sample users and passwords</h3> <% if current_user %> <% if current_user.admin? %> <h1 class='admin'><%= current_user.name.capitalize %> - Admininstrator</h1> <% elsif current_user.user? %> <h1 class='user'><%= current_user.name.capitalize %> - User</h1> <% end %> <% else %> <h1 class='not-signed-in'>Not currently signed in</h1> <% end %> <table style='width: 600px;'> <tr> <th>Name</th> <th>Email</th> <th>Role</th> <% if current_user %> <th>Impersonate</th> <% else %> <th>Password</th> <% end %> </tr> <% if current_user != true_user %> You (<%= true_user.name %>) are signed in as <%= current_user.name %> <% end %> <% User.all.each do |user| %> <tr> <td><%= user.name %></td> <td><%= user.email %></td> <td><%= user.role %></td> <td> <% if current_user %> <% if current_user.admin? %> <% if user.admin? && current_user != true_user %> <%= link_to "Back to #{user.name.capitalize}", stop_impersonating_user_path, data: { turbo_method: :post } %> <% elsif user.user? %> <%= link_to user.name.capitalize, impersonate_user_path(user), data: { turbo_method: :post } %> <% end %> <% else %> <% if user.admin? && current_user != true_user %> <%= link_to "Back to #{user.name.capitalize}", stop_impersonating_user_path, data: { turbo_method: :post } %> <% elsif current_user == true_user %> N/A <% else %> <% end %> <% end %> <% else %> password <% end %> </td> </td> </tr> <% end %> </table>
Version data entries
24 entries across 24 versions & 1 rubygems