Created
April 26, 2010 04:13
-
-
Save raholland79/378963 to your computer and use it in GitHub Desktop.
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 Account < ActiveRecord::Base | |
| has_many :users | |
| has_many :companies | |
| accepts_nested_attributes_for :users | |
| accepts_nested_attributes_for :companies | |
| validates_presence_of :name | |
| end | |
| class Company < ActiveRecord::Base | |
| belongs_to :account | |
| has_many :users, :through => :account | |
| has_many :brokerage_loads | |
| validates_presence_of :name | |
| end | |
| class User < ActiveRecord::Base | |
| belongs_to :account | |
| has_many :companies, :through => :account | |
| has_and_belongs_to_many :brokerage_loads | |
| validates_presence_of :login, :email, :name_first, :name_last | |
| acts_as_authentic do |c| | |
| #c.my_config_option = my_value # for available options see documentation in: Authlogic::ActsAsAuthentic | |
| end # block optional | |
| end | |
| class AccountsController < ApplicationController | |
| def new | |
| @account = Account.new | |
| @user = @account.users.build | |
| @company = @account.companies.build | |
| end | |
| def create | |
| @account = User.new(params[:account]) | |
| if @account.save | |
| flash[:notice] = "Account registered!" | |
| redirect_back_or_default account_url | |
| else | |
| render :action => :new | |
| end | |
| end | |
| end | |
| <!-- account/new.html.erb --> | |
| <%- form_for(@account) do |f| -%> | |
| <!-- Fields for new account --> | |
| <div> | |
| <h3>Account</h3> | |
| <%= f.label 'Account Name' %> | |
| <%= f.text_field :name %> | |
| </div> | |
| <br/> | |
| <!-- Fields for new company --> | |
| <%- f.fields_for :companies do |cf| -%> | |
| <div> | |
| <h3>Company</h3> | |
| <%= cf.label :name %> | |
| <%= cf.text_field :name %> | |
| </div> | |
| <%- end -%> | |
| <!-- Fields for new user --> | |
| <div> | |
| <h3>Initial Admin User</h3> | |
| <%- f.fields_for :users do |uf| -%> | |
| <%= uf.label :login %> | |
| <%= uf.text_field :login %> | |
| <br/> | |
| <%= uf.label 'First Name' %> | |
| <%= uf.text_field :name_first %> | |
| <br/> | |
| <%= uf.label 'Last Name' %> | |
| <%= uf.text_field :name_last %> | |
| <br/> | |
| <%= uf.label :password %> | |
| <%= uf.password_field :password %> | |
| <br/> | |
| <%= uf.label :password_confirmation %> | |
| <%= uf.password_field :password_confirmation %> | |
| </div> | |
| <br/> | |
| <%- end -%> | |
| <%= f.submit 'balls'%> | |
| <%- end -%> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment