开发者

Devise in Rails - partials?

开发者 https://www.devze.com 2023-02-07 03:51 出处:网络
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

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)

0

精彩评论

暂无评论...
验证码 换一张
取 消