
Uninitialized constant using polymorphic association
Reported by Rob | January 21st, 2009 @ 10:14 AM
Using a polymorphic association, I get an "uninitialized constant" error when I click on an order_by_link. For a test case, I set up the following example, where the regular association "post" works as expected, while the polymorphic association "resource" returns "uninitialized constant CatalogEntry::Resource" when clicking on their respective links. Using version 1.6.2.
I am a Rails noobie, my apologies if I'm missing something obvious, and thanks for a very useful plugin.
class CatalogEntry < ActiveRecord::Base
belongs_to :resource, :polymorphic => true
belongs_to :post
end
class Article < ActiveRecord::Base
has_one :catalog_entry, :as => :resource
end
class Post < ActiveRecord::Base
has_one :catalog_entry
end
create_table :catalog_entries
t.string :name
t.integer :resource_id
t.string :resource_type
t.integer :post_id
end
create_table :articles
t.text :content
end
create_table :posts
t.text :content
end
class Jquery::CatalogEntriesController < ApplicationController
def index
@search = CatalogEntry.new_search(params[:search])
@cats, @cats_count = @search.all, @search.count
end
end
<tr>
<th><%= order_by_link :id %></th>
<th><%= order_by_link :resource => :content %></th>
<th><%= order_by_link :post => :content %></th>
</tr>
<% @cats.each do |cat| %>
<tr>
<td><%= cat.id %></td>
<td><%= cat.resource.content%></td>
<td><%= cat.foo.content%></td>
</tr>
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป
Provides common named scopes and object based searching.