Skip to content

Instantly share code, notes, and snippets.

@lxyuma
Last active December 13, 2015 19:59
Show Gist options
  • Save lxyuma/4967124 to your computer and use it in GitHub Desktop.
Save lxyuma/4967124 to your computer and use it in GitHub Desktop.
# railsのmodelで***_path(resourceのURL)を使う方法
- Rails.application.routes.url_helpers.posts_path
- 参考
- http://stackoverflow.com/questions/5380703/rails-get-resource-path-in-model
- ところが、これだと、パスしか分からない。URLのホスト部分が入らない。
- posts_urlに変えると、以下のエラーが出る。
- ArgumentError (Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true):
- config/environments/***.rb
- Rails.application.routes.default_url_options[:host] = 'localhost:3000'
- 参考
- http://d.hatena.ne.jp/InvokeTwoA/20111121
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment