jeudi 6 juillet 2017

How to fix Country-State-Select gem undefined method issue?

In a implementation of gem: http://ift.tt/2tXriyB

When i go to Post Job new page show this error on the log

undefined method `country' for #

I've tried to put the

accepts_nested_attributes_for

in the job model, but did not worked.

Someone have any hint to spare?

Job Model

 class Job < ActiveRecord::Base

    belongs_to :user
    belongs_to :location
    accepts_nested_attributes_for :location, allow_destroy: true
    default_scope -> { order(created_at: :desc) }

    end

Location Model

 class Location < ActiveRecord::Base

    has_many :users
    has_many :jobs

    end

Job new view

 <%= simple_form_for @job do |f| %>
    <%= f.simple_fields_for :location do |l| %>
     <%= l.input :country, label: "Country", collection: CountryStateSelect.countries_collection %>
    <%= l.input :state, CountryStateSelect.state_options(label: "State / Province", form: f, field_names: { :country => :country, :state => :state } ) %>
    <%= l.input :city, CountryStateSelect.city_options(label: "City ", form: f, field_names: {  :state => :state, :city => :city } ) %>

          <% end %>
    <%= f.input :name, label: 'Name', error: 'Name is mandatory' %>
       <%= f.input :description, placeholder: 'user@domain.com' %>

    <%= f.button :submit %>
    <% end %>

Aucun commentaire:

Enregistrer un commentaire