ruby on rails - double nested form with devise and geocoder not showing -


i using complex nested form. have 3 models

location

class location < activerecord::base   has_many :events   has_many :profiles   geocoded_by :address end 

profile

class profile < activerecord::base   belongs_to :user   accepts_nested_attributes_for :user   belongs_to :location   accepts_nested_attributes_for :location end 

user (devise)

class user < activerecord::base   has_one :profile, dependent: :destroy   accepts_nested_attributes_for :profile end 

in user/new view

= form_for @user, validate: true, url: user_registration_path, html: { class: 'new-user form-default' } |f|   = f.fields_for :profile |p|     = p.fields_for :location |build|       = build.text_field :address, :input_html =>{:id => 'geo-input-address', :value => current_user.city.name}  

my problem address field not visible, why wouldn't rendering?

when creating new user, user not yet have profile or location. fields_for iterate on existing items.

either override devise controllers, , in new action can write like:

def new   @user = user.new   @user.build_profile   @user.profile.build_location end 

so providing @user-object empty profile , empty location, user can fill in.

a little easier, little dirtier straight in view (then not need override devise controllers).


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -