Hello Stackoverflow peeps,
I follow ryan bates railscast about using dynamic pages using the Ancestry gem. I wonder if there is a way to use multiple show pages.
For example I have sections and pages. I want to show a template for the sections and a template for the pages. currently this is my code.
Thanks in advance.
Controller
class PagesController < ApplicationController
before_filter :find_page, only: [:show, :edit, :update, :destroy]
def show
respond_to do |format|
format.html # show.html.erb
format.json { render json: @page }
end
end
private
def find_page
@page = Page.find_by_slug!(params[:id].split("/").last)
end
end
model
class Page < ActiveRecord::Base
attr_accessible :content, :name, :parent_id, :slug
validates :slug, uniqueness: true, presence: true,
exclusion: {in: %w[signup login]}
before_validation :generate_slug
has_ancestry
def to_param
slug
end
def generate_slug
self.slug ||= name.parameterize
end
def find_page
@page = Page.find_by_slug(params[:id].split('/').last)
end
end
I would like to have for example two different template for the show.html.erb page. Is that possible?