0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

新規投稿、ログイン、ログアウト実装時 pathの書き方注意点

Posted at

新規投稿、ログイン、ログアウト等ルートパスを記載する際の注意点を記載します!(めっちゃ初歩です)

app/views/shared/_header.html.erb
<%# CSS・・・assets/stylesheets/shared/header.css %>
<header class='top-page-header'>
  <div class='search-bar-contents'>
    <%= link_to image_tag("furima-logo-color.png", class:"furima-icon"), "/" %>
    <form class="search-form" action="#">
      <input class='input-box' placeholder='キーワードから探す'>
      <button class="search-button">
        <%= image_tag "search.png", class:"search-icon" %>
      </button>
    </form>
  </div>
  <div class='nav'>
    <ul class='lists-left'>
      <li><%= link_to 'カテゴリー', "#", class: "category-list" %></li>
      <li><%= link_to 'ブランド', "#", class: "brand-list" %></li>
    </ul>
    <ul class='lists-right'>
      <%# deviseを導入できたら、ログインの有無で表示が変わるように分岐しましょう%>
      <% if user_signed_in? %>
        <%= link_to current_user.nickname, "#{@user.name}", class: "user-nickname" %>
        <%= link_to 'ログアウト', "destroy_user_session_path" , method: :delete, class: "logout" %>
      <% else %>
        <%= link_to 'ログイン', "user_session_path", class: "login" %>
        <%= link_to '新規登録', "new_user_registration_path", class: "sign-up" %>
      <% end %>
      <%# //deviseを導入できたら、ログインの有無で表示が変わるように分岐しましょう%>
    </ul>
  </div>
</header>

上記だとpathにそのままアクセスしてしまう。

例)新規登録ボタンを押すと
⇒new_user_registration_pathへ直接アクセスする

これの解決方法として""を外すこと!たったこれだけ!!

app/views/shared/_header.html.erb
app/views/shared/_header.html.erb
<%# CSS・・・assets/stylesheets/shared/header.css %>
<header class='top-page-header'>
  <div class='search-bar-contents'>
    <%= link_to image_tag("furima-logo-color.png", class:"furima-icon"), "/" %>
    <form class="search-form" action="#">
      <input class='input-box' placeholder='キーワードから探す'>
      <button class="search-button">
        <%= image_tag "search.png", class:"search-icon" %>
      </button>
    </form>
  </div>
  <div class='nav'>
    <ul class='lists-left'>
      <li><%= link_to 'カテゴリー', "#", class: "category-list" %></li>
      <li><%= link_to 'ブランド', "#", class: "brand-list" %></li>
    </ul>
    <ul class='lists-right'>
      <%# deviseを導入できたら、ログインの有無で表示が変わるように分岐しましょう%>
      <% if user_signed_in? %>
        <%= link_to current_user.nickname, "#{@user.name}", class: "user-nickname" %>
        <%= link_to 'ログアウト', destroy_user_session_path , method: :delete, class: "logout" %>
      <% else %>
        <%= link_to 'ログイン', user_session_path, class: "login" %>
        <%= link_to '新規登録', new_user_registration_path, class: "sign-up" %>
      <% end %>
      <%# //deviseを導入できたら、ログインの有無で表示が変わるように分岐しましょう%>
    </ul>
  </div>
</header>

####※リンク先には""を付けないように注意が必要!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?