Kristiyan Tsvetanov Kristiyan Tsvetanov - 1 year ago 81
Ruby Question

Rails, unexpected tSYMBEG error

I found several questions on the same topic but they all have some problem with punctuation(missed or added a comma). In my case, I get the following error when migrating

SyntaxError: /home//workspace//app/models/user.rb:27:
syntax error, unexpected tSYMBEG, expecting keyword_do or '{' or '('

has_many :roles, through :positions

The user model:

class User < ActiveRecord::Base
has_many :positions
has_many :roles, through :positions

The role model:

class Role < ActiveRecord::Base
has_many :positions
has_many :users, through :positions

The position model:

class Position < ActiveRecord::Base
belongs_to :role
belongs_to :user

Any idea what might be the problem? Thank you!

Answer Source

through should be a symbol here:

has_many :roles, through: :positions

and here:

has_many :users, through: :positions

It is a hash key which is passed to has_many method, not a separate method.


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download