[Rails] Re: Associations join
I've just got a really basic setup to see if i got it working:
card.rb
class Card < ActiveRecord::Base
attr_accessible :attack, :defense, :name
has_many :cardlevels
has_many :users, :through => :cardlevels
end
cardlevel.rb
class Cardlevel < ActiveRecord::Base
attr_accessible :card_id, :level, :user_id
belongs_to :user
belongs_to :card
end
user.rb
class User < ActiveRecord::Base
attr_accessible :name
has_many :cardlevels
has_many :cards
end
-----------------------------------------------------
card_controller.rb
class CardController < ApplicationController
def show
@card = Card.all
end
end
User & cardlevel are empty for now
-----------------------------------------------------
<h1>Card#show</h1>
<p>Find me in app/views/card/show.html.erb</p>
<%= @card.user %>
Where i tried eaching the @card, tried @card.users, @card.user.name etc.
etc.
-----------------------------------------------------
The error:
Showing c:/tuts/kaartje/app/views/card/show.html.erb where line #3
raised:
undefined method `user' for #<Array:0x3c81ac8>
Extracted source (around line #3):
1: <h1>Card#show</h1>
2: <p>Find me in app/views/card/show.html.erb</p>
3: <%= @card.user %>
Rails.root: c:/tuts/kaartje
Application Trace | Framework Trace | Full Trace
app/views/card/show.html.erb:3:in
`_app_views_card_show_html_erb___1042037435_30519240'
Request
Parameters:
{"id"=>"show"}
-----------------------------------------------------
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home