Monday, November 14, 2011

Devise: User belongs_to organization

Devise is the most awesomist (yes, its a word) authentication plugin for rails. I have a scenario where, when the user registers they can also enter an organization. I have a clinical application where there is an admin who will have the ability to create users, so the initial user who creates an account (and an org) will then be able to create users who will also be associated with that org. Also, I wanted to do this without adding, modifying the devise registration controller.

Enough talk, heres the code. If you need tips on getting started with devise check out Ryan Bates screencasts here:

Here are my models:

Couple things to note here. I think the belongsto and nestedattribs is pretty straightforward. However, also note the :organizationattributes added to attraccessible.

Here is my view:

No comments:

Post a Comment