I''m seeing a strange problem with one of my belongs_to relationships. I''ve defined 3 belongs_to relationships on my Issue class as follows: class Issue < ActiveRecord::Base belongs_to :submitter, :class_name => "User", :foreign_key => "entered_by_id" belongs_to :assigned_to, :class_name => "User", :foreign_key => "assigned_to_id" belongs_to :status, :class_name => "IssueStatus", :foreign_key => "status_id" end My User class is currently empty: class User < ActiveRecord::Base end and my IssueStatus class looks like this: class IssueStatus < ActiveRecord::Base table_name "issue_statuses" end When I try to access an Issue from my rhtml file, I get an error on the status call: <% @issues.each {|issue| %> <tr> <td><%= issue.id %></td> <td><%= h issue.title %></td> <td><%= issue.submitter.login %></td> <td><%= issue.status.name %></td> <!-- This is line 24 --> <td><%= issue.assigned_to.login %></td> </tr> <% } %> The error is: Showing /project/show.rhtml where line #24 raised undefined method `status'' for #<Issue:0x249a98c> The issue.submitter.login and issue.assigned_to.login calls work as expected and I don''t see what''s different with the status call. This is on Rails 0.10.0 on OS X. Thanks! Todd Breiholz
On Thursday 10 March 2005 08:49 pm, Todd Breiholz wrote:> class IssueStatus < ActiveRecord::Base > table_name "issue_statuses" > endTry using "set_table_name". I believe this is a documentation bug.
That was it. Thanks, Caleb! On Fri, 11 Mar 2005 08:51:02 -0500, Caleb Tennis <caleb-aBrp7R+bbdUdnm+yROfE0A@public.gmane.org> wrote:> On Thursday 10 March 2005 08:49 pm, Todd Breiholz wrote: > > > class IssueStatus < ActiveRecord::Base > > table_name "issue_statuses" > > end > > Try using "set_table_name". I believe this is a documentation bug. > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
On a side note, I found that the word "status" in the plural is also converted to "status" in the singular. You could avoid having to set the table name explicitly if you follow that convention, though I personally don''t think of "status" as the plural either :) Duane Johnson (canadaduane) On Fri, 11 Mar 2005 09:11:49 -0600, Todd Breiholz <talanb-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> That was it. > > Thanks, Caleb! > > > On Fri, 11 Mar 2005 08:51:02 -0500, Caleb Tennis <caleb-aBrp7R+bbdUdnm+yROfE0A@public.gmane.org> wrote: > > On Thursday 10 March 2005 08:49 pm, Todd Breiholz wrote: > > > > > class IssueStatus < ActiveRecord::Base > > > table_name "issue_statuses" > > > end > > > > Try using "set_table_name". I believe this is a documentation bug. > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >