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

Ask A Question

Notifications

You’re not receiving notifications from this thread.

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

Damian Nelwep asked in Rails

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]

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 34,885+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.