[英]Rails: syntax error, unexpected tIDENTIFIER, expecting keyword_end
Ruby on Rails beginner here. Ruby on Rails初学者在这里。
Had this error in localhost:3000 在localhost:3000中发生此错误
ActiveRecord::PendingMigrationError Migrations are pending. ActiveRecord :: PendingMigrationError迁移正在挂起。 To resolve this issue, run: bin/rake db:migrate RAILS_ENV=development
要解决此问题,请运行:bin / rake db:migrate RAILS_ENV = development
I ran rake db:migrate in terminal and got this: 我在终端中运行了rake db:migrate并得到了这个:
$ rake db:migrate
rake aborted!
SyntaxError: /Users/EuphoriaComplex/src/bookmarks/db/migrate/20150407050503_add_user_to_bookmark.rb:5: syntax error, unexpected tIDENTIFIER, expecting keyword_end
add has_many :bookmarks to app/models/user.rb
^
/Users/EuphoriaComplex/src/bookmarks/db/migrate/20150407050503_add_user_to_bookmark.rb:7: syntax error, unexpected tIDENTIFIER, expecting keyword_end
add belongs_to :user to app/model/user.rb
^
And this is my code in bookmarks/db/migrate in Sublime: 这是我在Sublime中的书签/数据库/迁移中的代码:
class AddUserToBookmark < ActiveRecord::Migration
def change
add_column :bookmarks, :user_id, :integer
add has_many :bookmarks to app/models/user.rb
add belongs_to :user to app/model/user.rb
end
end
I was following this tutorial: http://12devs.co.uk/articles/writing-a-web-application-with-ruby-on-rails/ and I only made it to "Require authentication to manage your bookmarks" 我正在遵循本教程: http : //12devs.co.uk/articles/writing-a-web-application-with-ruby-on-rails/,而我只是将其设置为“需要身份验证才能管理您的书签”。
"Users have many Bookmarks" is the section in question. 有问题的是“用户有很多书签” 。
The error tells you exactly where the problem is. 该错误告诉您问题的确切出处。
add has_many :bookmarks to app/models/user.rb
add belongs_to :user to app/model/user.rb
this should not be in a migration since they do not change the schema. 这不应进行迁移,因为它们不会更改架构。 You need to add these to the bookmark and user model, so
您需要将它们添加到书签和用户模型中,因此
class Bookmark < ActiveRecord::Base
belongs_to :user
end
class User < ActiveRecord::Base
has_many :bookmarks
end
The relationships between models go in the models, the migrations are for the database, it is different... you should keep the add_column :bookmarks, :user_id, :integer
but the other two lines erase them from your migration, you shouldgo to your user.rb
model and add has_many :bookmarks
and go to your bookmark.rb
model and add belongs_to :user
模型之间的关系进入模型,迁移是针对数据库的,这是不同的...您应保留
add_column :bookmarks, :user_id, :integer
但其他两行将从迁移中删除它们,您应该转到user.rb
模型并添加has_many :bookmarks
并转到您的bookmark.rb
模型并添加belongs_to :user
Maybe you can also read this guide, it might help: http://guides.rubyonrails.org/index.html 也许您也可以阅读本指南,它可能会有所帮助: http : //guides.rubyonrails.org/index.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.