2

My application has 3 models : consultant, project and appointment I am using a nested form with simple_form gem

class Consultant < ActiveRecord::Base
  has_many :appointments
end

class Project < ActiveRecord::Base
  has_many :appointments, :dependent => :destroy
  accepts_nested_attributes_for :appointments, :allow_destroy => true
end

class Appointment < ActiveRecord::Base
  belongs_to :consultant
  belongs_to :project
end

My form is as follows :

= simple_nested_form_for(@project) do |f| 

  %div.field
    = f.input :name, :label => 'Nom du projet'
    = f.simple_fields_for :appointments do |builder|
      = render 'appointment_fields', :f => builder
    = f.link_to_add "ajouter un consultant", :appointments

  %div   
  %div.actions
    = f.submit

with the partial :

%p.fields
  = f.input :consultant_id, :input_html => { :class => 'special' }
  = f.association :consultant
  = f.input :nb_days, :input_html => { :class => 'special',:size => 10  }
  = f.input :rate, :input_html => {:size => 10}
  = f.link_to_remove "Remove this task"

Is it possible to do something as simple as this with simple_form ? The answer is YES : it works nicely

2
  • the erro is :/Users/herveleroy/Dropbox/compta/app/views/projects/_appointment_fields.html.haml where line #4 raised: Association :consultant not found Commented Jul 28, 2011 at 13:42
  • Association :consultant not found Commented Jul 28, 2011 at 13:44

1 Answer 1

2

The errors is because there is no association called consultant on the model Appointment. Use consultants instead.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.