In the Rails Guides under 2.5 Singular Resources, it states
Sometimes, you have a resource that
clients always look up without
referencing an ID. For example, you
would like /profile to always show the
profile of the currently logged in
user. In this case, you can use a
singular resource to map /profile
(rather than /profile/:id) to the show
action.
So I tried the example:
match "profile" => "users#show"
However, when I attempt to go to the profile_path, it attempts to redirect to the following, where id = :id:
/profile.id
This represents two issues:
- I dont want the id to be displayed at all, and thought this was a routing pattern to mask an id
- Using this method causes the following error. It also causes this error when I attempt to request user_path.
Error:
ActiveRecord::RecordNotFound in UsersController#show
Couldn't find User without an ID
I guess this is because the params being passed through look like this:
{"controller"=>"users", "action"=>"show", "format"=>"76"}
Am I using singular resources correctly?
My UsersController:
def show
@user = User.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @user }
end
end
My routes:
resources :users
match "profile" => "users#show"
Or
or