问题标签 [ruby-on-rails-4.1]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
1304 浏览

ruby-on-rails - Rails 重新加载类并“已从模块树中删除,但仍处于活动状态!” 参数错误

我在我的 Rails 应用程序中编写了自定义工具。我在这样的文件中启用它config/initializers/instrumentation.rb

但这会导致我出错A copy of FooBar::ControllerRuntime has been removed from the module tree but is still active!。我想我可以通过两种方式解决它:

  • 添加路径可能是“FooBar::ControllerRuntime is defined toconfig.autoload_one_paths ”
  • 定义:to_prepare回调ActionController::Railtie

第二种解决方案如下所示:

这么长的介绍引出了一个问题:哪种方式更好?首先,我禁止重新加载与我的FooBar::ControllerRuntime. 有了第二个,我觉得搞砸是不好的ActionController::Railtie。正确的知道ActionController::Railtie没有定义to_prepare,但是如果在下一个版本中会发生什么?

0 投票
1 回答
857 浏览

ruby-on-rails - 在 Rails 4 中下载文件显示没有 html 页面

我是 Ruby on Rails 的新手。我正在使用 Ruby 2 和 Rails 4。我想使用 rails 下载文件。但是当我输入路径时,它不会显示 html 页面,而是会打开一个下载框并单击“确定”它会下载。我的代码如下。如果有任何机构可以,请帮助我。谢谢你。

在控制器中:

在 download.html.erb 中:

0 投票
1 回答
967 浏览

ruby-on-rails - 在 Rails 4.1.1 中使用包含的“对象不支持#inspect”

我刚刚从 Rails 4.0.2 升级到 Rails 4.1.1,尝试includes在 ActiveRecord 查询中使用时看到了一些奇怪的行为。我在 Windows 7、64 位开发环境中。我定义了以下模型:

当我打开控制台并执行以下命令时,它们按预期工作

但是,执行以下命令,

在控制台中生成以下输出,

为什么这个调用会生成一条Object doesn't support #inspect消息?另外,如果我执行以下命令:

我得到以下堆栈跟踪

0 投票
1 回答
222 浏览

ruby-on-rails - 未初始化的常量 ActiveRecord::Transitions with rails 4.1 and transitions gem

我的实现是使用 rails 3.2 版。我正在尝试将我的应用程序升级到 rails 4.1,但后来我开始收到错误“未初始化的常量 ActiveRecord::Transitions”。根据 github ( https://github.com/troessner/transitions ) 上的转换 gem 文档,它应该可以与 rails >=4 一起使用,没有任何问题。

下面给出了带有转换的 active_record 类的代码。

我得到的错误是

虽然包括 gem

0 投票
1 回答
535 浏览

activeadmin - 使用 rails 4.1 的活动管理范围

我在使用 rails 4.1 的 Active Admin 中收到此错误

显示 ../bundler/gems/active_admin-ad33a0f6c772/app/views/active_admin/resource/index.html.arb 其中第 1 行提出:

ClassList::ActiveRecord_Relation:0xa9f44bc 的未定义方法“调用”

提取的源代码(第 1 行附近)

1 insert_tag renderer_for(:index)

下面是我正在使用的代码

ActiveAdmin.register ClassList do #.... scope :upcoming_classes #.. end

并在模型中

class ClassList < ActiveRecord::Base scope :upcoming_classes, where('class_date > ?', Date.today) end

请有人帮我解决这个错误吗?

谢谢,

0 投票
1 回答
918 浏览

activerecord - activeuuid 和 rails 4.1.1 兼容还是这里有问题?

这是我试图用来实现 gem activeuuid的一个小代码片段:

宝石文件

用户.rb

迁移xxxxxxxxx_create_users.rb

即使在捆绑或重新启动控制台之后,在这里执行一个简单的查询也不可行。

甚至

这里发生了什么错误。我是否缺少一些必需的依赖项。

0 投票
1 回答
707 浏览

ruby-on-rails - 从 heroku bash 在 heroku 上复制/安装 wkhtmltoimage

我正在使用wkhtmltoimage我的应用程序。将其部署到 heroku 时,它显示wkhtmltoimage找不到可执行文件,/usr/local/bin这意味着我必须将可执行文件安装或复制到 heroku 的本地/bin 文件夹我如何从 heroku bash 安装或复制到 /usr/local /bin 文件夹

0 投票
1 回答
887 浏览

form-submit - Rails 4 simple_form 字段取决于提交按钮单击

我有一个带有 2 个提交按钮的 simple_form,根据按钮单击,我希望有一个字段 :is_active 为真或假:

这是行不通的

0 投票
1 回答
12420 浏览

ruby-on-rails - 用户的未定义方法 attr_accessible 错误

我正在尝试创建各种登录。我创建了一个用户脚手架,并在我的 user.rb 中有这段代码

我不断收到此错误

0 投票
1 回答
137 浏览

ruby-on-rails - How do I create a base class that abstracts a has and belongs to many relationship in Rails 4.1

I have the following HABTM relation and corresponding logic that is identical in at least 3 different tables, so I wanted to factor it, and related methods, into a common base class. The problem is, even though the association does show up in the object's association_cache, trying to access it results in an exception (ArgumentError comparison of nil object with a string). I'm confused about why this isn't working, as this seems like basic OOP programming.

My base model is set up like this: