add files
[uma.git] / app / controllers / customers_controller.rb
blobe4541ca80f60eab18eddba7aa48852711f15d621
1 #coding: utf-8
2 class CustomersController < ApplicationController
4   # GET /customers/new
5   # GET /customers/new.xml
6   def new
7     @customer = Customer.new
9     respond_to do |format|
10       format.html # new.html.erb
11       format.xml  { render :xml => @customer }
12     end
13   end
15   # POST /customers
16   # POST /customers.xml
17   def create
18     @customer = Customer.new(params[:customer])
20     @exist_cust = Customer.find_by_mobile(@customer.mobile)
21     if @exist_cust.nil?
22       respond_to do |format|
23         if @customer.save
24           flash[:notice] = '用户资料已经记录,快来给你的宠物起名字。'
25           format.html { redirect_to :controller => :pets, :action => :new, :customer => @customer}
26           format.xml  { render :xml => @customer, :status => :created, :location => @customer }
27         else
28           format.html { render :action => "new" }
29           format.xml  { render :xml => @customer.errors, :status => :unprocessable_entity }
30         end
31       end
32     else
33       @customer = @exist_cust
34       flash[:notice] = '用户资料已经记录,快来给你的宠物起名字。'
35       redirect_to :controller => :pets, :action => :new, :customer => @customer
36     end
38   end
41 end