Note that there are some explanatory texts on larger screens.

plurals
  1. PONested Routing for Single Table Inheritance model rails 3.1
    primarykey
    data
    text
    <p>I created a Single table inheritance model in my model file and am having difficulty with the routing. When I use :as in my resource, it renames my named path.</p> <p>Model file:</p> <pre><code>class Account &lt; ActiveRecord::Base belongs_to :user end class AdvertiserAccount &lt; Account end class PublisherAccount &lt; Account end </code></pre> <p>Routes.rb </p> <pre><code>resources :advertiser_accounts, :as =&gt; "accounts" do resources :campaigns end </code></pre> <p>I used :as in my routes because it is a single table inheritance and I want to pass the account_id and not the advertiser_account_id. My link is <a href="http://127.0.0.1:3000/advertiser_accounts/1/campaigns" rel="nofollow">http://127.0.0.1:3000/advertiser_accounts/1/campaigns</a> </p> <pre><code>/advertiser_accounts/:account_id/campaigns/:id(.:format) </code></pre> <p>However, using :as renames my named path from advertiser_account_campaigns to account_campaigns. My route looks like</p> <pre><code>account_campaigns GET /advertiser_accounts/:account_id/campaigns(.:format) campaigns#index </code></pre> <p>So when I create a new item using form_for, I would get "undefined method `advertiser_account_campaigns_path'"</p> <p><strong>Edited: current hacked solution</strong></p> <p>A hack around way that I am using is to duplicate the code in the routes file. Anyone have suggestions?</p> <pre><code>resources :advertiser_accounts, :as =&gt; "accounts" do resources :campaigns end resources :advertiser_accounts do resources :campaigns end </code></pre>
    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