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:

http://railscasts.com/episodes/209-introducing-devise http://railscasts.com/episodes/210-customizing-devise

Here are my models: https://gist.github.com/1336517

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: https://gist.github.com/1336513

No comments:

Post a Comment