初心者です。
layout内のapplication.html.erbでheaderを統一しています。
login後、index.htmlでは、表示されるのですが、そこからリンクでshow.htmlへ飛んでも、同じように表示されるようにするにはどうすれば良いでしょうか?リンクからとぶとヘッダー内の要素が全て消えてしまいます。
applicatin.html.erb
<% if user_signed_in? %>
</tr> </header> <% end %><ul class ="header-username"><%= g_info.name %></ul> <ul class ="mypagecommand"><%= link_to 'Mypage', g_info_path(g_info.id) %></ul> <ul ul class ="mypagecommand"><a href="#">Chat</a></ul> <ul class ="mypagecommand"><%= link_to 'News', news_path(g_info.id) %></ul> <ul class ="mypagecommand"><%= link_to 'Q&A', questions_path %></ul> <ul class ="mypagecommand"><%= link_to "LOGOUT", logout_path %></ul> <% end %> <% end %>
<% if current_user == nil %>
<header> <tr> <div class = "dropdown-header"> <ul class ="responsive-menu"><i class="fas fa-bars"></i></ul> <div class ="dropdown-content-header"> <%= link_to 'SIGNUP' ,new_guide_path %> <a href="#">LOGIN</a> </div> </div> <ul class ="logo"><a href="/g_infos">JAPA<span>N</span>IGHT</a></ul> <ul class ="login"><%= link_to 'LOGIN', login_path %></ul> </tr> </header> <% end %>g_infos_controller.erb
lass GInfosController < ApplicationController
before_action :set_g_info, only: [:show, :edit, :update, :destroy]
GET /g_infos
GET /g_infos.json
def index
@g_infos = GInfo.all
end
GET /g_infos/1
GET /g_infos/1.json
def show
@g_info = GInfo.find(params[:id])
end
GET /g_infos/new
def new
@g_info = GInfo.new
end
GET /g_infos/1/edit
def edit
@g_info = GInfo.find(params[:id])
end
routes.rb
Rails.application.routes.draw do
resources :news
resources :questions
resources :g_infos
mount RailsAdmin::Engine => '/admin', as: 'rails_admin'
devise_for :admin_users
resources :guides
devise_for :users
For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
root 'g_infos#index'
get "/" => "g_infos#index"
get "/g_infos/new" => "g_infos#new"
get '/g_infos/:id' => 'g_infos#show'
get '/g_infos/:id/edit' => 'g_infos#edit'
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/08/09 08:53