Created
August 16, 2011 10:12
-
-
Save onlymejosh/1148780 to your computer and use it in GitHub Desktop.
This file contains 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 | |
accepts_nested_attributes_for :users | |
validates_presence_of :company, :on => :create, :message => "can't be blank" | |
end | |
class User < ActiveRecord::Base | |
belongs_to :account | |
attr_accessible :email, :password, :password_confirmation, | |
:first_name, :last_name, :company | |
has_secure_password | |
validates_presence_of :first_name, :on => :create, :message => "can't be blank" | |
validates_presence_of :last_name, :on => :create, :message => "can't be blank" | |
validates_presence_of :email, :on => :create, :message => "can't be blank" | |
validates_uniqueness_of :email, :on => :create, :message => "has already been taken" | |
validates_presence_of :password, :on => :create | |
end | |
# Accounts Controller | |
def create | |
@account = Account.new(params[:account]) | |
# create recurly account | |
respond_to do |format| | |
if @account.save | |
format.html { redirect_to login_path, notice: 'Congratulations! Please use the form belog to access Arctic Fox.' } | |
else | |
format.html { render action: "new" } | |
end | |
end | |
end | |
So where would I run the validation? It only needs to be done on the creation of account not for each user | |
Can I access user from accounts even before its been saved? | |
This is the code I need to run. Preferable | |
account = Recurly::Account.new( | |
:account_code => 'rachael', | |
:first_name => 'Rachael', | |
:last_name => 'Test', | |
:email => 'rachael@test.com', | |
:company_name => 'Chicago, Inc' | |
) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment