Created
November 9, 2011 21:00
-
-
Save jonpaul/1353010 to your computer and use it in GitHub Desktop.
Devise nested form issue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h2>Sign up</h2> | |
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %> | |
<%= devise_error_messages! %> | |
<% f.object.build_organization unless f.object.organization %> | |
<% f.fields_for :organization do |o| %> | |
<p><%= o.label :name %><br/> | |
<%= o.text_field :name %></p> | |
<% end %> | |
<p><%= f.label :email %><br /> | |
<%= f.email_field :email %></p> | |
<p><%= f.label :password %><br /> | |
<%= f.password_field :password %></p> | |
<p><%= f.label :password_confirmation %><br /> | |
<%= f.password_field :password_confirmation %></p> | |
<p><%= f.submit "Sign up" %></p> | |
<% end %> | |
<%= render :partial => "devise/shared/links" %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Organization < ActiveRecord::Base | |
belongs_to :boss, :class_name => 'User', :foreign_key => 'owner_id', :dependent => :destroy | |
has_many :listings, :dependent => :destroy | |
has_many :peons, :class_name => 'User', :dependent => :destroy | |
has_many :exports, :dependent => :destroy | |
attr_accessible :name, :owner_id, :phone, :address, :city, :state, :zip, :country, :contact_email, :website, :hashed_id | |
after_create :write_hash | |
. | |
. | |
. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
. | |
. | |
. | |
<h2>Sign up</h2> | |
<form accept-charset="UTF-8" action="/users" class="user_new" id="user_new" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /><input name="authenticity_token" type="hidden" value="qtJsSVcfrd8augc+U2kHqHYgOWuIqi1D8jM1nS/Prjc=" /></div> | |
<p><label for="user_email">Email</label><br /> | |
<input id="user_email" name="user[email]" size="30" type="email" value="" /></p> | |
<p><label for="user_password">Password</label><br /> | |
<input id="user_password" name="user[password]" size="30" type="password" /></p> | |
<p><label for="user_password_confirmation">Password confirmation</label><br /> | |
<input id="user_password_confirmation" name="user[password_confirmation]" size="30" type="password" /></p> | |
<p><input id="user_submit" name="commit" type="submit" value="Sign up" /></p> | |
</form> | |
<a href="/users/sign_in">Sign in</a><br /> | |
<a href="/users/password/new">Forgot your password?</a><br /> | |
<a href="/users/unlock/new">Didn't receive unlock instructions?</a><br /> | |
</div> | |
. | |
. | |
. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Base | |
# Include default devise modules. Others available are: | |
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable | |
devise :database_authenticatable, :registerable, | |
:recoverable, :rememberable, :trackable, :validatable, | |
:lockable, :timeoutable | |
# Setup accessible (or protected) attributes for your model | |
has_many :roles, :through => :assignments | |
has_one :organization, :foreign_key => 'owner_id', :dependent => :destroy | |
has_many :peons, :class_name => 'User', :through => :organization, :foreign_key => 'organization_id' | |
belongs_to :company, :class_name => 'Organization', :foreign_key => 'organization_id', :dependent => :destroy | |
accepts_nested_attributes_for :organization | |
attr_accessible :email, :email_confirmation, :password, :password_confirmation, | |
:first_name, :last_name, :job_title, :organization_attributes, :organization_id,:remember_me | |
. | |
. | |
. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment