Forum: Ruby on Rails Routes: Root as Users#Show

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
9ceeb190da20a2917644da86dbcd2322?d=identicon&s=25 Tim Conner (plump)
on 2008-11-04 12:52
Hi,
I'd like to define the root path of my site as the Users#Show action,
therefore whenever someone goes to http://www.example.com they will see
their own profile page.
At the moment I have done this by having the following in my routes.rb
file:
  # Home Page
  map.root :controller => 'users', :action => 'show'

The Users controller then looks like:
  def show
    @user = current_user
  end

This works with respect to showing each users profile page on the route
page.  However, if tries to go to http://www.example.com/users/anything
they still see their profile page because I am setting @user to
current_user no matter what the request.
I need to return 404 pages when users go to:
http://www.example.com/users/anything_other_than_their_id

What is the correct way to do this?
Thanks
D188e591eac11021329b8821a5f954c7?d=identicon&s=25 Ar Chron (railsdog)
on 2008-11-04 21:26
In the controller, couldn't you look for/at params[:id] to see if the
request was for a user other than themselves?
This topic is locked and can not be replied to.