Skip to main content
Ask A Question
Notifications
You’re not receiving notifications from this thread.
Subscribe

Do I have to create a controller for users using Devise or where can I find its actions ?

Rails • Asked by Damian Nelwep

I'm having some trouble setting up Paperclip gem to setup profile pictures for the users of my app and I need to access users_controller. Since I'm using Devise, I don't really know where I can find it and I guess it's not a really good idea to create users_controller.rb since it may surely get to some conflicts so where should I go to solve this ? It took some time for me to find a way but without success I'll keep on searching anyways. Wishing you a good day/night and thank you so much for the support...


Before you can customize them you need to generate them:

rails generate devise:controllers users

https://github.com/plataformatec/devise/wiki/Tool:-Generate-and-customize-controllers

Then for devise to use your generated controllers, you add a controllers option to your routes:

devise_for :users, :controllers => { registrations: 'users/registrations' }


You should generate a users_controller which inherits from application_controllerand 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]


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 31,152+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.