【发布时间】:2022-01-16 03:46:02
【问题描述】:
我用的是Windows10+Ubuntu18.04
我在模型中设置了“has_many”,但启动rails控制台时出现错误消息:
/home/keaton/.rvm/rubies/ruby-2.6.6/bin/ruby: warning: shebang line ending with \r may cause problems
/home/keaton/.rvm/gems/ruby-2.6.6/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require': /mnt/c/projects/Kasuri/app/models/user.rb:8: syntax error, unexpected tSYMBEG, expecting do or '{' or '('
has_many :spaces, through: :space_users
^ (SyntaxError)
但我确定我没有拼写错误,rb文件的源代码如下:
class User < ApplicationRecord
devise :database_authenticatable, :registerable,
#:recoverable, :rememberable, :validatable
has_many :space_users, dependent: :destroy
has_many :spaces, through: :space_users
has_many :channel_users, dependent: :destroy
has_many :channels, through: :channel_users
has_many :messages, dependent: :destroy
end
我正在使用 Devise 来制作登录功能。这是异常的原因吗?谢谢!
【问题讨论】:
标签: ruby-on-rails devise