Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a `Users` show page using Devise

I'm trying to create a User show page (that will function as a profile page) but am confused about how to do this with Devise. It doesn't seem as though Devise comes with any sort of show definition - is there any way I can access the controllers Devise is implementing in order to make one or do I have to override them?

like image 976
steffi2392 Avatar asked Aug 17 '11 00:08

steffi2392


People also ask

What is devise in Ruby?

Devise is the cornerstone gem for Ruby on Rails authentication. With Devise, creating a User that can log in and out of your application is so simple because Devise takes care of all the controllers necessary for user creation ( users_controller ) and for user sessions ( users_sessions_controller ).


2 Answers

You should generate a users_controller which inherits from application_controller and define there your custom show method. Don't forget to create a view and routes for it. Ex:

#users_controller.rb def show   @user = User.find(params[:id]) end  #in your view <%= @user.name %>  #routes.rb match 'users/:id' => 'users#show', via: :get # or  get 'users/:id' => 'users#show' # or resources :users, only: [:show] 
like image 91
Sergey Kishenin Avatar answered Sep 23 '22 08:09

Sergey Kishenin


Don't forget that your users routes should be below the devise_for users routes, like this:

#routes.rb devise_for :users resources :users, :only => [:show] 

Also, if you are using a username or an email as the primary key instead of the usual id, you should avoid routing conflicts by declaring your routes as follow:

#routes.rb devise_for :users, :path_prefix => 'd' resources :users, :only => [:show] 
like image 42
Ashitaka Avatar answered Sep 23 '22 08:09

Ashitaka