Reputation: 267040
I have multiple versions of a document:
about_version1.html
about_version2.html
about_version3.html
In my controller I want to render the text from either version 1,2 or 3.
I want to also use a layout.
How can I load the contents file with a layout? Is there built-in way in rails to read from a static asset like this?
Upvotes: 1
Views: 328
Reputation: 3298
Of course. Rails will use /views/layouts/application.html.erb
as the default layout for all templates. To use a different layout, create a file in /views/layouts
called about.html.erb
and put <%= yield %>
where you want to insert your template.
Then assuming you have all three template files under /views/static
, do something like this:
## static_controller.rb
def about
version = params[:version]
render "static/about_version#{version}.html.erb", layout: "about"
end
Your will need to supply the param :version
when you call #about
of course.
Upvotes: 1