I’m building a Rails 3 app, where I need to give users specific roles based on the path they take to sign up on the site. I am using Devise and Cancan.
So for instance, the path
new-fundraiser (or /users/new/fundraiser)
Needs to set user.fundraiser = true on user creation, and
new-charity-user (or /users/new/charity)
Needs to set user.charity_owner = true on user creation.
What is the easiest / best-practice way to accomplish this using Devise and Cancan?
I would set up a route like:
In your user model I’d add an accessor:
Then in your users#new.html.erb form add a hidden field:
Then your won’t need to change your controller code at all.