Created
June 1, 2009 14:57
-
-
Save leehambley/121462 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
%ul | |
=f.hidden_field :tag | |
%li | |
=f.label :line_1 | |
=f.text_field :line_1 | |
%li | |
=f.label :line_2 | |
=f.text_field :line_2 | |
%li | |
=f.label :city | |
=f.text_field :city | |
%li | |
=f.label :county | |
=f.text_field :county | |
%li | |
=f.label :postcode | |
=f.text_field :postcode |
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
-form_for @customer do |customer_form| | |
%fieldset | |
%legend User Fields | |
=render :partial => 'users/new_form', :locals => {:f => customer_form} | |
-customer_form.fields_for :account_address do |account_address_form| | |
%fieldset | |
%legend Address Fields | |
=render :partial => 'addresses/form', :locals => {:f => account_address_form} | |
- if @customer.is_business? | |
%fieldset | |
%legend Business Fields | |
=render :partial => 'users/business_fields', :locals => {:f => customer_form} | |
%fieldset | |
%legend | |
= customer_form.submit 'Register' |
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 CustomersController < ApplicationController | |
before_filter :new_customer, :only => [:new] | |
before_filter :find_customer, :only => [:edit, :update] | |
before_filter :already_logged_in, :only => [:new] | |
def show | |
@customer = Customer.find(params[:id]) | |
end | |
def new | |
# debugger | |
end | |
def create | |
@customer = Customer.new(params[:customer]) | |
respond_to do |format| | |
if @customer.save_without_validation | |
format.html { redirect_to(edit_customer_path(@customer)) } | |
format.xml { render :xml => @customer, | |
:status => :created, | |
:location => :customer | |
} | |
else | |
format.html { render :action => :new } | |
format.xml { render :xml => @customer.errors, | |
:status => :unprocessable_entity | |
} | |
end | |
end | |
end | |
def edit | |
# @customer = Customer.find(params[:id]) | |
# # @customer.account_address = Address.new(:tag => 'account-address') | |
end | |
def update | |
debugger | |
@customer.attributes = params[:customer] | |
# @customer.account_address.attributes = params[:customer][:account_address_attributes] | |
respond_to do |format| | |
if @customer.save! | |
flash[:notice] = 'Customer was successfully saved.' | |
format.html { redirect_to(customer_path(@customer)) } | |
format.xml { head :ok } | |
else | |
format.html { render :action => "edit" } | |
format.xml { render :xml => @customer.errors, | |
:status => :unprocessable_entity } | |
end | |
end | |
end | |
private | |
def already_logged_in | |
if logged_in? | |
flash[:notice] = "Already Logged In!" | |
render :template => 'customers/new_when_logged_in' | |
end | |
end | |
def new_customer | |
@customer = Customer.new | |
build_customer | |
end | |
def find_customer | |
@customer = Customer.find(params[:id]) | |
build_customer | |
end | |
def build_customer | |
@customer ||= Customer.new | |
@customer.build_addresses unless @customer.addresses | |
@customer.build_account_address(:tag => 'account-address') unless @customer.account_address | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment