开发者

Log In - if Admin direct to Admin Index 1st

I have the 'user' log-ins all set up and working. I would like to change it so that when an Admin or Moderator logs in - they are directed to the /admin/index page 1st so they can preview new posts?

Would also like to add a 'Home' link for all 'users' to sit neatly beside the 'sign in' and 'sign up' links, not sure how I do it in this code block?

Any code solutions would be appreciated...

views/layouts/application.html.erb

<div id="user_nav">
    <% if user_signed_in? %>
        Signed in as <%= current_user.email %>. Not you?
        <%= link_to "Sign Out", destroy_user_session_path %>
    <% else %>
        <%= link_to "Sign Up", new_user_registration_path %> or
        <%= link_开发者_C百科to "Sign In", new_user_session_path %>
    <% end %>
</div>


You can add the home link before or after the if/else/end block:

<div id="user_nav">
    <%= link_to "Home", root_path %>
    <% if user_signed_in? %>
        Signed in as <%= current_user.email %>. Not you?
        <%= link_to "Sign Out", destroy_user_session_path %>
    <% else %>
        <%= link_to "Sign Up", new_user_registration_path %> or
        <%= link_to "Sign In", new_user_session_path %>
    <% end %>
</div>

or

<div id="user_nav">
    <% if user_signed_in? %>
        Signed in as <%= current_user.email %>. Not you?
        <%= link_to "Sign Out", destroy_user_session_path %>
    <% else %>
        <%= link_to "Sign Up", new_user_registration_path %> or
        <%= link_to "Sign In", new_user_session_path %>
    <% end %>
    <%= link_to "Home", root_path %>
</div>

As for directing the Admin or Moderator to a different page on signup, you could detect a user's role in the controller that handles new_user_session_path and redirect_to /admin/index if they are that type of user.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜