Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Take a look at this rails cast - <a href="http://railscasts.com/episodes/117-semi-static-pages" rel="nofollow">http://railscasts.com/episodes/117-semi-static-pages</a></p> <p>I agree that what you are trying to do isn't really 'the rails way', but I use the techniques in the above link whenever I am creating pages such as about us and privacy pages which generally have a block of text and will potentially be updated in the future.</p> <p>In a nutshell what you have to do is create a model called content_page which has a link (string), and content (text) and heading (string). Then you create a controller with just a show action which will look like so -</p> <pre><code> class ContentPagesController &lt; ApplicationController def show @content_page = ContentPage.find_by_permalink(params[:link]) raise ActiveRecord::RecordNotFound, "Page not found" if @content_page.nil? end end </code></pre> <p>And in your view for your show action you can say things like -</p> <pre><code> @content_page.content @content_page.heading </code></pre> <p>to get the content and heading for that record (or whatever other attributes you assign to ContentPage).</p> <p>Then in your routes you can have something like this at the bottom of your routes.rb (you put it at the bottom because it is a greedy route) -</p> <pre><code> match ':link' =&gt; 'content_pages#show' </code></pre> <p>So now you can say www.mywork.com/nike which will find the content page with nike as the link. I'm being very brief because it is well worth watching that rails cast.</p> <p>Like I said though, the above technique is only good for basic content pages, you should really have a controller for each page, even if it just has an index action :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload