Reputation: 347
Hi I'd like to accomplish having a URL that's
users/edit
instead of the current
users/7/edit
I have my own auth system built upon omniauth. Thus I store their user_id in a session. How would I go about accomplishing this task?
Upvotes: 1
Views: 170
Reputation: 17834
Assuming that you use current_user
, even if you are using something else just replace current_user
with your method, I am using current_user
here, follow these steps,
Create an action, I would name it edit_user
in your users controller
def edit_user
@user = current_user # or User.find(session[:user_id])
end
Add routes to routes.rb
get "/users/edit" => "users#edit_user"
You are done, you can use the above route anywhere in the application, you can also name the route if needed.
OR, if you don't want to define a new action and want to use the existing edit
action, do this
Remove routes for edit
from the default resources
routes and then manually define it. In this way, you can use the existing edit
action
resources :users, except: [:edit]
get "/users/edit" => "users#edit"
Hope this helped!
Upvotes: 3