How to make a page through the admin panel?
There is a documents resource and an appropriate controller:
class DocumentsController < ApplicationController def index @documents = Document.all.paginate(page: params[:page], per_page: 10) end def admin_index @documents = Document.all.paginate(page: params[:page], per_page: 10) render layout: "admin" end def show @document = Document.find(params[:id]) end def admin_show @document = Document.find(params[:id]) render layout: "admin" end .... .... end There are 2 layouts:
application.html.erb, admin.html.erb The index controller displays a list of documents in the public part of the site (application.html.erb). The admin_index controller displays a list of documents in a closed part of the site (admin.html.erb).
in the public part of the site I can view any document by clicking on the 'show' link:
<% @documents.each do |document| %> <%= document.title %> <%= link_to 'Show', document %> <% end %> the problem is that in the closed part of the site I cannot see any document by clicking the link:
<%= link_to 'Show', document %> It throws me to the page of a specific document, but layout: application.html.erb, and I need layout: admin.html.erb
routes:
Testpager::Application.routes.draw do get "admin/index" resources :news, only: [:index, :show] resources :documents, only: [:index, :show, :destroy] get "contacts/index" get "services/index" get "index/index" get "admin/index" get "admin/documents" => 'documents#admin_index' get "admin/documents/:id" => 'documents#admin_show' root 'index#index' end