Geocoder
を使用して,userがsignupする際にuserのcountry_idにgeocoderの機能を使って自動的にcountry_idを設定したいのですが詰まっています。
user自身にcountry カラムを持たせれば簡単にできるのですが、association先のオブジェクトを検索して設定する方法がわかりません!
# Table name: countries # id :integer not null, primary key # name :string default(""), not null # alpha2 :string default(""), not null class Country < ApplicationRecord has_many :users end $ > rails console $ > Country.first #<Country:0x007fd399d8ee00> { :id => 1, :name => "Andorra", :alpha2 => "AD", {
# == Schema Information # Table name: users # id :integer not null, primary key # email :string default(""), not null # country_id :integer not null class User < ApplicationRecord belongs_to :country end
あなたの回答
tips
プレビュー