LoginSignup
25
19

More than 5 years have passed since last update.

controller,view以外からurl_forを呼ぶ

Last updated at Posted at 2014-03-03

意外と簡単だったがggってもなかなかヒットしなかったのでメモ。

やりたいこと

  • rake タスクからurl_forを使ってとあるURLを作成したい
    • routs.rbでごにょごにょしてる部分があるので、url_forで解決したい
  • root_pathも呼びたい

解決方法

routes = Rails.application.routes.url_helpers
url = routes.url_for(host: "example.com", controller: "users", action: "show", id: 1)
rootpath = routes.root_path

以下じゃできなかった
* http://lxyuma.hatenablog.com/entry/2013/02/17/002744
* http://steve.dynedge.co.uk/2010/04/29/rails-3-rake-and-url_for/

25
19
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
25
19