I have a habtm relationship and want to return a category for an
article. for some reason it wants to return strange values and no
results. I get this error doing a reference
undefined method `name'' for #<Array:0x22ef54c>
Here''s the code excerpts:
#Article Model
has_and_belongs_to_many :categories
#Category Model
has_and_belongs_to_many :articles
#Articles Controller has this variable used in the erb below
#edited
@article = Article.find(:all, :conditions => ''published =
1'', :order => ''articles.created_at DESC'', :include
=>
[:categories, :comments, :user])
index.rhtml
<% @article.each do |article| -%>
<div class="post">
<h2><%= link_to article.title, :action => "post", :id
=> article %></h2>
<small>Published in <%= link_to "#{article.categories.name}",
:action
=> "category", :id => article.categories.id %>
#blah blah blah
<% end -%>
why does categories.id return a strange array of numbers and it say
there is no method "name" when there is a column with
"name"? I have
no problems with any other type of relationships except the habtm,
which I need the many-to-many relationship here. What am I doing wrong?
The Foreign Keys are there and correct, that was the first thing I
checked. And this type of declarations work else where, is there
something else I''m missing.
J Brien | HybridIndie Productions | hybridindie.com |
iam-QLwuMy0vUAhCl22TKe+ceQ@public.gmane.org