Class: Refinery::Customers::CustomersController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Refinery::Customers::CustomersController
- Defined in:
- app/controllers/refinery/customers/customers_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
-
#edit ⇒ Object
GET /customers/:id/edit.
- #new ⇒ Object
-
#update ⇒ Object
PUT /customers/:id.
Instance Method Details
#create ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/controllers/refinery/customers/customers_controller.rb', line 59 def create @customer = Customer.new(params[:customers_customer]) @customer.username = @customer.email if @customer.save @customer.roles << ::Refinery::Role[:customer] # remember as a customer role sign_in( @customer) # forces devise to login this user redirect_to refinery.stores_root_path else @customer.errors.delete(:username) # this is set to email render :action => :new end end |
#edit ⇒ Object
GET /customers/:id/edit
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/controllers/refinery/customers/customers_controller.rb', line 17 def edit @billing_address = ( @customer.billing_address.nil? ? ::Refinery::Addresses::Address.new( :email => @customer.email ) : @customer.billing_address ) @shipping_address = ( @customer.shipping_address.nil? ? ::Refinery::Addresses::Address.new( :email => @customer.email ) : @customer.shipping_address ) end |
#new ⇒ Object
12 13 14 |
# File 'app/controllers/refinery/customers/customers_controller.rb', line 12 def new @customer = Customer.new end |
#update ⇒ Object
PUT /customers/:id
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/controllers/refinery/customers/customers_controller.rb', line 31 def update @billing_address, @shipping_address = ::Refinery::Addresses::Address.update_addresses( @customer, params ) fields = ( params[:user].nil? ? :customers_customer : :user ) if params[fields][:password].blank? and params[fields][:password_confirmation].blank? params[fields].delete(:password) params[fields].delete(:password_confirmation) end # keep these the same params[fields][:username] = @customer.email if @customer.update_attributes(params[fields]) && @billing_address.errors.empty? && @shipping_address.errors.empty? flash[:notice] = t('successful', :scope => 'customers.update', :email => @customer.email) redirect_to refinery.stores_root_path else render :action => 'edit' end end |