25
19

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

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

以下じゃできなかった

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?