Kristiyan Tsvetanov Kristiyan Tsvetanov - 4 months ago 22
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
end


The role model:

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


The position model:

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


Any idea what might be the problem? Thank you!

Answer

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.

Documentation

Comments