I have a User model that I am using devise for. Each User belongs_to a Group. I am trying to find an easy way to set a user's group on sign up - without creating a custom controller to override devise?.
My models look like this:
class User < ActiveRecord::Base
belongs_to :group
end
class Group < ActiveRecord::Base
has_many :users
end
Here's the form:
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<%= f.label :email %><br />
<%= f.email_field :email %>
<%= f.label :password %><br />
<%= f.password_field :password %>
<%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation %>
<%= label_tag :group_name %>
<%= text_field_tag :group_name %>
<%= f.submit "Sign up" %>
Since I'm only trying to save this one additional attribute (group_name), I would like to avoid creating a whole new custom devise controller. Is there a way to save a user's group at the model level - with a callback maybe? Or is there a better way to save a group on sign up?
Thanks!