【发布时间】:2014-09-19 02:38:13
【问题描述】:
所以,我正在尝试为我的开发需求构建一个快速控制台程序,类似于rails console(我正在使用 Sinatra + DataMapper + pry)。
我运行它并启动cat = Category.new(name: 'TestCat', type: :referential)。它给了我以下错误:
Error: Cannot open "/home/art-solopov/Projects/by-language/Ruby/billy-bones/=" for reading.
问题的原因可能是什么?
控制台:
#!/usr/bin/env ruby
$LOAD_PATH << 'lib'
require 'pry'
require 'config'
binding.pry
lib/config.rb:
# Configuration files and app-wide requires go here
require 'sinatra'
require 'data_mapper'
require 'model/bill'
require 'model/category'
configure :production do
DataMapper::Logger.new('db-log', :debug)
DataMapper.setup(:default,
'postgres://billy-bones:billy@localhost/billy-bones')
DataMapper.finalize
end
configure :development do
DataMapper::Logger.new($stderr, :debug)
DataMapper.setup(:default,
'postgres://billy-bones:billy@localhost/billy-bones-dev')
DataMapper.finalize
DataMapper.auto_upgrade!
end
configure :test do
require 'dm_migrations'
DataMapper::Logger.new($stderr, :debug)
DataMapper.setup(:default,
'postgres://billy-bones:billy@localhost/billy-bones-test')
DataMapper.finalize
DataMapper.auto_migrate!
end
lib/model/category.rb:
require 'data_mapper'
class Category
include DataMapper::Resource
property :id, Serial
property :name, String
property :type, Enum[:referential, :predefined, :computable]
has n, :bills
# has n, :tariffs TODO uncomment when tariff ready
def create_bill(params)
# A bill factory for current category type
case type
when :referential
ReferentialBill.new params
when :predefined
PredefinedBill.new params
when :computable
ComputableBill.new params
end
end
end
如果我在控制台脚本中用 irb 代替 pry,就可以了。
非常感谢!
P. S.
好的,昨天我再次尝试了这个脚本,它运行良好。我没有更改任何内容。我不确定现在是否应该删除该问题。
P. P.S.
或者实际上不是……今天我又遇到了。仍然完全不知道可能导致它的原因。
** 已解决 **
该死的你撬!
好的,这就是区别。
当我第二次测试时,我实际上输入了a = Category.new(name: 'TestCat', type: :referential) 并且它起作用了。看起来 pry 只是认为 cat 是 Unix 命令,而不是有效的变量名。
【问题讨论】:
标签: ruby sinatra ruby-datamapper pry