Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Rendering an action doesn't make sense. You'll want to render a template (or a file) with a layout.</p> <pre><code># Path relative to app/views with controller's layout render :template =&gt; params[:path] # ... OR # Absolute path. You need to be explicit about rendering with a layout render :file =&gt; params[:path], :layout =&gt; true </code></pre> <p>You could serve a variety of different templates from a single action with page caching.</p> <pre><code># app/controllers/static_controller.rb class StaticController &lt; ApplicationController layout 'static' caches_page :show def show valid = %w(static1 static2 static3) if valid.include?(params[:path]) render :template =&gt; File.join('static', params[:path]) else render :file =&gt; File.join(Rails.root, 'public', '404.html'), :status =&gt; 404 end end end </code></pre> <p>Lastly, we'll need to define a route.</p> <pre><code># config/routes.rb map.connect 'static/:path', :controller =&gt; 'static', :action =&gt; 'show' </code></pre> <p>Try accessing these static pages. If the path doesn't include a valid template, we'll render the 404 file and return a 404 status.</p> <ul> <li><code>http://localhost:3000/static/static1</code></li> <li><code>http://localhost:3000/static/static3</code></li> <li><code>http://localhost:3000/static/static2</code></li> </ul> <p>If you take a look in app/public you'll notice a static/ directory with static1.html, static2.html and static3.html. After accessing the page for the first time, any subsequent requests will be entirely static thanks to page caching.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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