Topic: another has_many problem

Ok, I've been trying to make this for a few weeks now, and I just keep getting errors.

I'm trying to make a database to show what games a user owns. My attempts are as follow.

create_ownerships.rb

t.column user_id, :integer
t.column game_id, :integer

user.rb
has_many :games, :through => :ownerships

game.rb
has_many :users, :through => :ownerships

Re: another has_many problem

You need:

has_many :ownerships

Before the ":through" association of each model. If you still get an error, post the message here.

Railscasts - Free Ruby on Rails Screencasts

Re: another has_many problem

app/models/game.rb:4: syntax error, unexpected tSYMBEG, expecting kEND
  has_many :ownerships

ownership.rb

  belongs_to :user
  belongs_to :game

Re: another has_many problem

Can you post more of the code? What is on line 4?

Railscasts - Free Ruby on Rails Screencasts

Re: another has_many problem

Line 4 is the has_many ownerships

game.rb

class Game < ActiveRecord::Base
  belongs_to :console, :order => "created_at".
 
  has_many :ownerships
  has_many :users, :through => :ownerships
 
 
  GAME_NAME_MAX_LENGTH = 50
  GAME_NAME_SIZE = 20
 
  validates_format_of :game_name,
    :with => /^[A-Z0-9_ ]*$/i,
    :message => "must contain only letters, numbers, " +
                                  "and underscores"
 

end


could the code in my rhtml be messing it up by asking the wrong query?

<table>
  <% @user.games.each do |game| %>
  <tr>
    <td><%= link_to game.game_name, profile_for(game) %></td>
    <td>
      <% unless hide_edit_links? %>
        <%= link_to "Delete",
                    { :controller => "usergame", :action => "delete",
                      :id => game.game_name },
                    :confirm =>
                    "Really delete relationship with #{game.game_name}?" %>
      <% end %>
    </td>
  </tr>
  <% end %>
</table>

Re: another has_many problem

The problem is the period at the end of line 2 in the model, try removing it.

Railscasts - Free Ruby on Rails Screencasts

Re: another has_many problem

I just need a little monkey that sits on top of my shoulder and goes <ee ee ah ah> everytime I typo.