小编dar*_*ves的帖子

Ruby:Class.new在rails控制台中给出"Class not initialized"错误

我正在创建一个轻量级应用程序来创建和显示即将发生的事件的信息.我定义了一个Event类,它将args hash作为参数.初始化方法定义如下.

class Event < ActiveRecord::Base

  def initialize(args={})
    @what       = args[:what]
    @theme      = args[:theme]
    ... 
  end
end
Run Code Online (Sandbox Code Playgroud)

到现在为止还挺好.然后,在Rails控制台中,我定义了一个args哈希,并尝试创建一个Event实例,但得到以下错误.

[4] pry(main)> args = {what: 'what', theme: 'theme'}
=> {:what=>"what", :theme=>"theme"}
[5] pry(main)> Event.new(args)
=> #<Event not initialized>
Run Code Online (Sandbox Code Playgroud)

这看起来非常简单,但我无法搞清楚.任何帮助表示赞赏.

ruby ruby-on-rails

9
推荐指数
1
解决办法
5937
查看次数

rails 4.0 中 sass-rails 助手“image_url”和“asset_url”之间的区别?

我的 /app/assets/images 目录中有一个 jpg,我将它用作具有以下 CSS 的背景。

body {
  background-image: image_url('metal_texture.jpg')
}
Run Code Online (Sandbox Code Playgroud)

asset_url 助手也适用于这种情况。由于 Rails 4 资产管道不关心文件放置在 /app/assets 中的哪个目录,是否有理由使用 image_url 与 asset_url?

css ruby-on-rails sass

1
推荐指数
1
解决办法
2565
查看次数

Rails控制台错误:加载〜/ .pryrc时出错:命令:未找到`continue`

当我在我当前的笔记本电脑上使用rails控制台时(在任何rails项目上),当控制台启动时出现以下错误.

Rails console error: Error loading ~/.pryrc: Command: `continue` not found
Run Code Online (Sandbox Code Playgroud)

控制台仍然正常加载和运行,但我似乎无法弄清楚错误的原因.

这是.pryrc的内容.

Pry.config.pager = false
Pry.config.color = true
Pry.commands.alias_command 'c', 'continue'
Pry.commands.alias_command 's', 'step'
Pry.commands.alias_command 'n', 'next'
Run Code Online (Sandbox Code Playgroud)

如果我删除第三行并运行rails控制台,错误我得到一个类似的错误,引用'step'代替.该错误不会影响我的故障排除能力,但我真的很想了解潜在的问题.

ruby rails-console ruby-on-rails-4 pry-rails

1
推荐指数
1
解决办法
1037
查看次数