简体   繁体   中英

Devise in Rails - partials?

i started using Devise for authentication in one of my Rails projects. It seems that it creates some views under the folder 'devise' but they are not partials. I'm wondering, what happens if i want to include login or register view in another controller ? It seems that it cannot be rendered from any other controllers. How can i get a partial for login , register etc ?

I have a folder called "menu" inside /app/views/devise/

In there are 2 partials:

_login_items.html.erb

<% if user_signed_in? %>
  <li><%= link_to('Logout', destroy_user_session_path) %></li>
<% else %>
  <li><%= link_to('Login', new_user_session_path)  %></li>
<% end %>
<li>User: 
  <% if current_user %>
    <%= current_user.full_name %>
  <% else %>
    (not logged in)
  <% end %>
</li>

_registration_items.html.erb

<% if user_signed_in? %>
  <li><%= link_to 'Dashboard', dashboard_path %></li>
<% else %>
  <li><%= link_to 'Sign up', new_user_registration_path  %></li>
<% end %>

Then, in any of my layouts I want to include login/registration stuff, I do something like:

<div id="header">
  <ul>
  <li>Some common nav item</li>
  <%= render 'devise/menu/login_items' %>
  </ul>
</div>

I believe I learned the method from this tutorial (which is quite good)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM