刘华佼的全栈学习记录

如何让登陆和退出功能生效

| Comments

目标:

让这个网站有实际“登录”、“退出”的功能

步骤一:

app/views/common/_navbar.html.erb登录栏修改为:

           <% if !current_user %>
              <li><%= link_to("注册", new_user_registration_path) %> </li>
              <li><%= link_to("登录", new_user_session_path) %></li>
            <% else %>
              <li class="dropdown">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                    Hi!, <%= current_user.email %>
                    <b class="caret"></b>
                </a>
                <ul class="dropdown-menu">
                    <li> <%= link_to("退出", destroy_user_session_path, method: :delete) %> </li>
                </ul>
              </li>
            <% end %>

步骤二:
app/assets/javascripts/application.js中加入
//= require bootstrap/dropdown

Comments

comments powered by Disqus