Creating custom pages with Ruby on Rails

I am creating a personal site with Ruby on Rails. For the most part, RoR is an ideal tool for blogging, commenting, etc. Everything is pretty simple.

However, I want to have several pages that do not require any particular model. For example, the "About Me" page is necessary, and yet does not guarantee its own model / controller. In addition, these "singleton" pages will be linked to my default layout and should be accessible even when there are no objects created.

Is there a good way to handle this? I have seen many RoR sites that have separate pages, while preserving pretty URLs, but never showing how they are structured. Finally, can these individual pages be made dynamic? I would prefer not to have static html, if at all avoided.

+3
source share
2 answers

There is a Railscast about this subject that can answer your question:

http://railscasts.com/episodes/117-semi-static-pages

I have used this solution several times in my Rails applications.

+7
source

Usually I create a β€œstatic” controller, for example AboutController.

ruby script/generate controller about

, : index, contact, terms... routes.rb.

map.about 'about/:action', :controller => "about"

<%= link_to "Contact", about_path(:action => "contact") %>

, .

class AboutController < ApplicationController
  caches_page :index, :contact, ...
end

. "" , .

+2

Source: https://habr.com/ru/post/1713486/


All Articles