To access url helpers (url_for, etc) from Rails console (Rails 3)


/ Published in: Rails
Save to your folder(s)

in Rails 2, use `include ActionController::UrlWriter` instead.


Copy this code and paste it in your HTML
  1. include Rails.application.routes.url_helpers
  2.  
  3. # set host in default_url_options:
  4. default_url_options[:host] = "localhost"
  5.  
  6. # can then use:
  7. url_for()
  8.  
  9. # can check existing routes:
  10. edit_user_url(User.first)
  11. => "http://localhost/user/1/edit"

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.