- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
/billy-bones/=" for reading' while using pry and DataMapper-6ren"> /billy-bones/=" for reading' while using pry and DataMapper-因此,我正在尝试构建一个快速控制台程序来满足我的开发需求,类似于 rails console(我正在使用 Sinatra + DataMapper + pry)。 我运行它并启动 cat = Cate-6ren">
因此,我正在尝试构建一个快速控制台程序来满足我的开发需求,类似于 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
如果我在控制台脚本中将 pry 替换为 irb,一切正常。
非常感谢!
P. S.
好的,昨天我再次尝试了这个脚本,它运行得很好。我没有更改任何内容。我不确定现在是否应该删除问题。
P. P.S.
或者其实不是……今天又遇到了。仍然完全不知道可能导致它的原因。
** 已解决 **
你他妈的 pry !
好的,这就是区别。
当我第二次测试它时,我实际上输入了 a = Category.new(name: 'TestCat', type: :referential)
并且它起作用了。看起来 pry 只是认为 cat
是一个 Unix 命令,而不是一个有效的变量名。
最佳答案
不回答窥探问题我只是通常讨厌 ruby
中的 case 语句。
为什么不改变:
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
到:
def create_bill(params)
# A bill factory for current category type
self.send("new_#{type}_bill",params)
end
def new_referential_bill(params)
ReferentialBill.new params
end
def new_predefined_bill(params)
PredefinedBill.new params
end
def new_computable_bill(params)
ComputableBill.new params
end
你可以让它更动态,但我认为在这种情况下这会降低可读性,但如果你喜欢在 rails
中,这应该可以解决问题
def create_bill(params)
if [:referential, :predefined, :computable].include?(type)
"#{type}_bill".classify.constantize.new(params)
else
#Some Kind of Handling for non Defined Bill Types
end
end
或者这将在 rails
内部或外部工作
def create_bill(params)
if [:referential, :predefined, :computable].include?(type)
Object.const_get("#{type.to_s.capitalize}Bill").new(params)
else
#Some Kind of Handling for non Defined Bill Types
end
end
关于ruby - '错误 : Cannot open "/home/<...>/billy-bones/=" for reading' while using pry and DataMapper,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24986252/
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题? Update the question所以它是on-topic对于堆栈溢出。 9年前关闭。 Improve this que
我们正在尝试从 c3p0 迁移到 bonecp 连接池。我们使用 hibernate 作为 ORM 工具。 现在,有没有什么方法可以监控 boncecp 中的连接,比如了解特定时间点池中的最大可用连接
我正在尝试整合 Assimp 骨骼动画。按照这个tutorial 供引用。 我正在尝试的更改是使用固定功能管道。 问题:位置、纹理坐标和法线数据都很好,但我无法弄清楚教程中提到的四个骨骼和每个顶点的权
机器详细信息: Linux beaglebone 3.8.13-bone47 armv7l GNU/Linux 问题详情: 试图在 beagle bone black 上编写 out-of-tree
我想在 beagle bone black 上使用 qt,就像我们在桌面上使用的一样,没有“交叉编译”和“工具链”的东西。我已经使用 为运行 raspbian wheezy 的树莓派完成了此操作 ap
您能帮我解决 npm install 功能的一些神秘行为吗?“Npm install骨头”安装旧版本的下划线(1.1.7)而不是1.4.2。问题是旧版本包含几个错误,导致我的代码出现问题。 骨头目录中
我正在使用 Opengl 和 Jbox2d 用 Java 编写实时 2d 游戏。 我想开始编写网络组件。 虽然它使用 box2d,但我的游戏非常小,我想使用 Kryonet 库创建一个基本架构。
我在 Xcode 4.2 中创建了一个基本的应用程序。非常简单的应用程序,我没有改变任何东西。按下运行,您将获得标准的基本应用程序窗口。如果我为我的目标打开权限并点击运行,我不会收到任何调试器错误,但
我正在寻找一种将 Ubuntu 版本定制为实时操作系统的方法,然后将其安装在 Beagle Bone Black 上。我不知道从哪里开始。 安装在 Beagle Bone Black 上的 Ubunt
问题我遇到的问题是由以下操作引起的:当我将 BBB 连接到我的 PC 时(使用 USB 电缆),我不小心格式化了包含入门文件的 ~92 MB 分区。 因此,每次我给 BBB 通电时,USB LED 都
我实现了一个带有软件皮肤的 MD5 Loader。 md5 中的绑定(bind)姿势是最终的、绝对位置和旋转,您只需要计算与关节相关的权重。 我试图实现 GPU 蒙皮,但我被困在了一个点上。由于这些坐
在我的 centos 机器上交叉编译 Beagle Bone Black。 我正在创建一个应用程序“BasicComponentsTest.cpp”,它使用我创建并内置到静态库中的“SimFrameP
我是 linux 和 Beagle Bone Black 的新手。如果有人帮助解决我的问题,这将对我的项目进入下一个阶段非常有帮助。我在 Netbeans 中成功开发了一个 xml 阅读器并清理并构建
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a softwar
我有一个使用 bones wordpress 主题构建的网站。无论我做什么,我似乎都无法使用 wordpress enqueue 函数对 css 和 js 进行版本控制。 骨头里有什么东西吗,也许是我
我绞尽脑汁,网上试图在 BBB 上自学 PWM。我是 Python 和黑比格犬骨的新手。我想做的就是用我的电压表检查 PWM,看看它是否在变化,但代码一直在崩溃,使用: 预装了 Debian GNU/
我拼命想让我的 BBB 上的 PRU 正常工作。我所说的工作是指我想将引脚 P8 39-46 (GPIO2[6-13]) 用作由 PRU 控制的快速输出。 我在 SD 上安装了 BBB 的 debia
基本上音频披风正在工作。除了一种奇怪的现象让我感到困惑。我会尽力解释。 当我播放 .wav 文件时,例如 speaker-test -t vaw -> 如果幸运的话,我会听到预期的左前 - 右前。但是
我正在 Beaglebone Black 上进行一些图像处理,并且对在我的算法中使用 float 与 double 的性能增益感兴趣。 我尝试为此设计一个简单的测试: main.c #define M
如果我的 BBB 板是将暂停或恢复。 所以我添加了一个钩子(Hook)脚本 #! /bin/sh #/etc/pm/sleep.d/15_myapp case "$1" in susp
我是一名优秀的程序员,十分优秀!