Answer the question
In order to leave comments, you need to log in
Why is the content of the rails view not being displayed?
Layouts
app/views/layouts/admin.html.erb:
<!DOCTYPE html>
<html>
<head>
<title>Shop</title>
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= stylesheet_link_tag 'admin', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'admin', 'data-turbolinks-track': 'reload' %>
</head>
<body>
<%= render "shared/main_menu" %>
</body>
</html>
class Admin::BaseController < ApplicationController
layout 'admin'
end
class Admin::TextZonesController < Admin::BaseController
before_action :set_text_zone, only: [:show, :edit, :create, :update]
def index
@text_zones = TextZone.all
end
def show
end
def new
@text_zone = TextZone.new
end
def edit
end
def create
if @text_zone.save
redirect_to edit_text_zone_path(@text_zone), notice: 'Текстовая зона добавлена.'
else
render action: :new
end
end
def update
if @text_zone.update_attributes(params[:text_zone])
redirect_to edit_text_zone_path(@text_zone), notice: 'Текстовая зона успешно обновлена'
else
render action: :edit
end
end
def destroy
@text_zone.destroy
redirect_to text_zone_index_path, notice: 'Текстовая зона успешно удалена'
end
private
def set_text_zone
@text_zone = TextZone.find(params[:id])
end
end
<h1>Текстовые зоны</h1>
<div class="container">
<div class="row">
<div class="col-sm-4">
<h3>Название</h3>
<p>Lorem ipsum dolor..</p>
<p>Ut enim ad..</p>
</div>
<div class="col-sm-4">
<h3>Отображается</h3>
<p>Lorem ipsum dolor..</p>
<p>Ut enim ad..</p>
</div>
<div class="col-sm-4">
<h3>Описание</h3>
<p>Lorem ipsum dolor..</p>
<p>Ut enim ad..</p>
</div>
</div>
</div>
Rails.application.routes.draw do
root to: "application#index"
namespace :admin do
root to: 'main#index'
get 'main/index'
resources :text_zones
end
end
Answer the question
In order to leave comments, you need to log in
because in admin.html there is no template output from the controller
in app/views/layouts/admin.html.erb, you need to add
instead of yield, the content from the template will be rendered
<!DOCTYPE html>
<html>
<head>
<title>Shop</title>
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= stylesheet_link_tag 'admin', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'admin', 'data-turbolinks-track': 'reload' %>
</head>
<body>
<%= render "shared/main_menu" %>
<%= yield %>
</body>
</html>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question