【发布时间】:2019-01-19 11:46:57
【问题描述】:
我的代码:
class Song < ActiveRecord::Base
belongs_to :artist
has_many :song_genres
has_many :genres, :through :song_genres
end
错误:
rake aborted!
SyntaxError: .../app/models/song.rb:4: syntax error, unexpected ':', expecting keyword_end
has_many :genres, :through :song_genres
当我使用“=>”时:
class Song < ActiveRecord::Base
belongs_to :artist
has_many :song_genres
has_many :genres, :through => :song_genres
end
我不再收到错误消息,但现在我在一次迁移中收到另一条类似情况的错误消息。
rake aborted!
SyntaxError: .../db/migrate/01_create_artists_table.rb:4: syntax error, unexpected tSYMBEG, expecting keyword_end
t.string :name
那里的代码如下所示:
class CreateArtistsTable < ActiveRecord::Migration
def change
create_table :artists |t|
t.string :name
t.has_many :songs
t.has_many :genres, through: :song_genres
end
end
end
我是新手,非常感谢您的帮助!谢谢! :)
【问题讨论】:
标签: ruby activerecord migration syntax-error rake