Note that there are some explanatory texts on larger screens.

plurals
  1. PORoutes, path helpers and STI in Rails 4.0
    primarykey
    data
    text
    <p>This is driving me crazy! I have the two models <code>Lion</code> and <code>Cheetah</code>. Both inherit from <code>Wildcat</code>.</p> <pre><code>class Wildcat &lt; ActiveRecord::Base; end class Lion &lt; Wildcat; end class Cheetah &lt; Wildcat; end </code></pre> <p>STI is used here.</p> <p>They all get handled through the controller <code>WildcatsController</code>. There, I have a <code>before_filer</code> to get the <code>type</code> of wildcat from the <code>params[:type]</code> and all the other stuff to use the correct class.</p> <p>In my <code>routes.rb</code>, I created the following routes:</p> <pre><code>resources :lions, controller: 'wildcats', type: 'Lion' resources :cheetahs, controller: 'wildcats', type: 'Cheetah' </code></pre> <p>If I now want to use the path helpers, that I get from the routes (<code>lions_path</code>,<code>lion_path</code>,<code>new_lion_path</code>, etc.), everything is working as expected, except the <code>show</code> and the <code>new</code> paths. For example <code>lions_path</code> returns the path <code>/lions</code>. The <code>new</code> path returns <code>/lions/new?type=Lion</code>. Same with the <code>show</code> path. When I try to enter <code>/lions/new</code> to my root domain it correctly adds the type param in the background.</p> <p>So, my question is, why does Rails add the <code>type</code> parameter to the url if I use the path helper? And why only for <code>new</code> and <code>show</code>?</p> <p>I am running Rails 4.0.0 with Ruby 2.0 using a fresh Rails app.</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.
 

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