Friday, 17 April 2015

Absolute URL / Full URL in Rails 4

Rails 4

Controller:

def absolute_url
  request.base_url + request.original_fullpath
end

Action Mailer Notable changes in 4.2 release:


http://guides.rubyonrails.org/4_2_release_notes.html

  • link_to and url_for generate absolute URLs by default in templates, it is no longer needed to pass only_path: false. (Commit)
View:

If you use the _url suffix, the generated URL is absolute. Use _path to get a relative URL.



<%= link_to "User Home", user_url %>



No comments:

Post a comment