【发布时间】:2015-08-25 17:29:32
【问题描述】:
我正在发现 Sinatra 并开始使用它。一切都很棒,直到教程要求我需要一个 irb 中的文件,以便 IRB 可以使用 Song 类:
irb> require './song'
我完全按照教程进行操作,但是,我不断收到以下相同的错误消息:
MacBook-Pro-de-doguria:views arnaud$ ls
about.slim home.slim not_found.slim styles.scss
contact.slim layout.slim song.rb
MacBook-Pro-de-doguria:views arnaud$ irb
irb(main):001:0> require './song'
/Users/arnaud/Google Drive/Code/codebasics/sinatra2/views/song.rb:1: warning: encountered \r in middle of line, treated as a mere space
SyntaxError: /Users/arnaud/Google Drive/Code/codebasics/sinatra2/views/song.rb:1: syntax error, unexpected tIDENTIFIER, expecting end-of-input
DataMapper.s...rations'
^
from /usr/local/Cellar/ruby/2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /usr/local/Cellar/ruby/2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from (irb):1
我的文件song.rb是从教程中复制粘贴的,可以在下面找到:
require 'dm-core'
require 'dm-migrations'
DataMapper.setup(:default, "sqlite3://#{Dir.pwd}/development.db")
class Song
include DataMapper::Resource
property :id, Serial
property :title, String
property :lyrics, Text
property :length, Integer
property :released_on, Date
end
DataMapper.finalize
- 我尝试了单引号和双引号。
- 我检查了 Google 上所有可能的答案,堆栈溢出,你说的。
- 我的文件
song.rb在正确的文件夹中,我也检查了。 - 我删除并重新创建了两次 song.rb 文件,只是为了确保它不是复制粘贴的。
- 其他文件工作正常,我创建的视图工作正常。
您可以猜到,我对编程还很陌生,如果我忽略了一些非常基本的东西,请提前道歉。 干杯。
【问题讨论】:
-
我认为该文件有错误,我们需要查看文件顶部的确切内容
-
require "./song" => true我无法重现它,所以我最好猜你使用的是 Windows 风格的行尾?哦,我很确定views不是您的模型 (song.rb) 的正确文件夹,但这与您的问题无关。 -
谢谢,如上所述,我真的在学习如何将 ruby 付诸实践,所以基本上我正在按照我的教程所说的(关于 song.rb 文件的位置)。