私は2つのモデルとアドレスモデルを持っています
class Address < ActiveRecord::Base
attr_accessible :address1, :address2, :country, :county, :customer_id, :town
belongs_to :customer
end
そして顧客モデル
class Customer < ActiveRecord::Base
attr_accessible :email, :firstname, :lastname, :password, :phone
has_one :address
end
足場を使用して生成した CRUD 機能があります。私ができるようにしたいのは、新しい顧客を追加するときに、ファイルの住所から顧客の住所を選択するか、住所を選択しないことです。これを使用して、顧客とその住所を表示できます。
def showaddress
@customer = Customer.find(params[:id])
@address = @customer.address
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @customer }
end
end
これは、新しい顧客を作成するために使用される現在のコントローラーです
def new
@customer = Customer.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @customer }
end
end
したがって、基本的に私がやりたいことは、新しい顧客を作成するときに、ユーザーがクリックして住所を顧客に関連付けることができる住所のドロップダウンリストがあることです