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...

Reply

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' }

Reply

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]

Reply
Join the discussion
Create an account Log in

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

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

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