Ask A Question


You’re not receiving notifications from this thread.

Devise with additional user fields, nested models / attributes and custom routes

Dan Tappin asked in Gems / Libraries

I have posted a few related questions on this but now I am at a road block. I had this system working quite well and then I went to add to it and now I broke it real good!

First off I just discovered Gist so here is my code:

The idea here is that I have a single User login that can eventually be tied to multiple Companies via the Role.

You signup via Devise on the custom /register route and fill out the Company information etc. The custom registration controller creates the Role during the user creation and sets a few other attributes.

When I try to create a new user / company the additional user fields (name_first & name_last) always fail validation regardless if they are in fact valid. The nested Company fields do not validate at all. If I enter the email and password field only the form works but only creates the User record.

To me it seems like the custom registration controller is not being processed at all because it seems to not want to allow my additional params specified in sign_up_params


Hmmm... took my routes and tried this for fun:

devise_for :users, :skip => [:sessions], :controllers => { :registrations => 'users/registrations', :sessions => 'users/sessions' }
as :user do
get '/signin' => 'devise/sessions#new', :as => :new_user_session
post '/signin' => 'devise/sessions#create', :as => :user_session
delete '/signout' => 'devise/sessions#destroy', :as => :destroy_user_session

I wanted to see if the normal Devise routes work and they do except that now the validation fails completely. If I submit a blank form I get all kinds of errors but if I fill it out it works fine now. I am getting close but obviously missing something small here.


I think I figured it out. I stumbled across this:

I switched my routes to "user/..." from "devise/..." and that seemed to do the trick.


Oh nice. I rarely tend to customize Devise routes so it has been a while since the last time I did it. Glad the gist you found worked!

Join the discussion
Create an account Log in

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

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

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