【问题标题】:rails url helper in model模型中的rails url助手
【发布时间】:2012-12-07 06:49:13
【问题描述】:

我正在尝试访问我在 event 控制器中使用的 url 帮助程序,例如 event_url(event)

有没有办法在我的event 模型中访问它?

这样的?

event_url(self)

我正在使用 rails v2.3.11。

【问题讨论】:

标签: ruby-on-rails


【解决方案1】:

尝试在你的模型中添加这个

include ActionController::UrlWriter

您还需要将配置行添加到 env 配置: development.rb

config.action_controller.default_url_options = {:host => "localhost:3000"} 

生产.rb

config.action_controller.default_url_options = {:host => "example.com"} 

【讨论】:

  • 我试过了,但没有用。 #<0x111f502c8>
  • &gt;&gt;
猜你喜欢
  • 1970-01-01
  • 2015-08-27
  • 2011-09-16
  • 2011-08-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多