0

I am looking for a way to retrieve the URL path of a page, specifically, the full path to my blog post.

I would be looking for a way to retrieve this entire URL: http://example.com/posts/1

I am able to get this far: http://example.com/posts, however, I cannot find a way to dynamically pickup the id (1) at the end.

How should I do this?

Thanks.

  • see http://stackoverflow.com/questions/2165665/how-do-i-get-the-current-url-in-ruby-on-rails – tihom Sep 22 '13 at 20:46

1 Answers1

0

Try using request.original_url

http://api.rubyonrails.org/classes/ActionDispatch/Request.html#method-i-original_url

Edit:

routes.rb

Stovf::Application.routes.draw do
  resources :posts
end

posts_controller.rb

class PostsController < ActionController::Base
  def show
    # This is actually not needed for the example to work.
  end
end

posts/show.html.erb

<%= request.original_url %>

And the result is: enter image description here

dobrinov
  • 594
  • 4
  • 11