Rails.application.routes.url_helpers崩溃Heroku应用程序 [英] Rails.application.routes.url_helpers crashing Heroku app

查看:95
本文介绍了Rails.application.routes.url_helpers崩溃Heroku应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为Collection + Json构建一个序列化程序,并且我正在编写一个API例。在Heroku上部署的应用程序中使用 Rails.application.routes.url_helpers 时遇到问题。



我在一个序列化程序中使用它:

Rails.application.routes.url_helpers.bills_url



在开发中,一切正常。然而,在Heroku上这会产生一个错误:

#< Module:0x007f3a1eab8d58>未定义方法'bills_url' (NoMethodError)



如果我转储 Rails.application.routes.url_helpers.methods ,没有 _url _path 方法被列出。但是,他们是如果我在控制台中运行相同的代码:

  heroku run rails c --app myapp 
> Rails.application.routes.url_helpers.methods
> #=> :bills_url存在

这很奇怪。任何线索? Heroku是否使 url_helpers 不可用?我绝对失去了。我搜索了很多,但没有发现任何东西。



以下是 bug报告为完整跟踪。

谢谢。

解决方案

我遇到了同样的问题,发现是由于以下两个原因造成的:

首先,使用Rails.application.routes.url_helpers类常量中的方法,如下面的代码片段所示:

  class myObject 
包含ActiveModel :: Model

attr_accessor:id,:link

DEFAULT_OBJECT = new id:1,
link:Rails.application.routes.url_helpers.my_object_url({:id => 1})

...
end

其次,设置<$ c

所以结果是,当 config.eager_load = config.eager_load = true 真正的,动态网址助手并不是regi在加载myObject类时加密。



这篇文章可能有用 - > http://blog.arkency.com/2014/11/dont-forget-about-eager-load-when-extending-autoload /


I'm building a Serializer for Collection+Json, and I'm writing an API as an example. I'm having an issue when using Rails.application.routes.url_helpers on the deployed app on Heroku.

I use this in one serializer:

Rails.application.routes.url_helpers.bills_url

In development, everything works fine. However, on Heroku this raises an error:

undefined method 'bills_url' for #<Module:0x007f3a1eab8d58> (NoMethodError).

If I dump Rails.application.routes.url_helpers.methods, no _url or _path methods are listed. However, they are if I run the same code in the console:

heroku run rails c --app myapp
> Rails.application.routes.url_helpers.methods
> # => :bills_url is present

This is weird. Any clue on this? Does Heroku make url_helpers not available? I am absolutely lost. I've googled a lot but found nothing.

Here's the bug report for the complete trace.

Thank you.

解决方案

I had this same problem and found that is was caused due to 2 reasons:

First, using the Rails.application.routes.url_helpers methods in class constants like in the following snippet:

class myObject
  include ActiveModel::Model

  attr_accessor :id, :link

  DEFAULT_OBJECT = new id: 1, 
                     link: Rails.application.routes.url_helpers.my_object_url({:id => 1})

   ...
end

Second, setting config.eager_load = true in the environment file.

So result being, when config.eager_load = true, the dynamic url helpers haven't been registered when the myObject class is loaded.

This article maybe useful -> http://blog.arkency.com/2014/11/dont-forget-about-eager-load-when-extending-autoload/

这篇关于Rails.application.routes.url_helpers崩溃Heroku应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆