ruby on rails - How to make simple_form present my nested attributes -


survey & result linked this:

class survey < activerecord::base   has_many :results   accepts_nested_attributes_for :results end  class result < activerecord::base   belongs_to :survey end 

result has following columns in table:

create_table "results", :force => true |t|   t.integer  "survey_id"   t.integer  "field_id"   t.boolean  "selected",      :default => false end 

it has following virtual attribute:

class result < activerecord::base   def name     self.field.name.gsub("{{input}}", self.input)   end end 

i want form survey list results, highest point result lowest point result.

each result should tied radio box 1 can true @ time.

so far, form looks this:

= simple_form_for [@competitor, @survey] |f|   = f.simple_fields_for :result, f.object.results.sort{ |a,b| b.points <=> a.points}.each |r|     = r.input :selected, :label => r.object.name   = f.button :submit, :id => 'submit_survey' 

for trouble, i'm getting following error:

undefined method `name' #<enumerator:0x007fb8075d3038> 

how can achieve have in mind?

iterating on results should this, i'm not sure if it's enough make radios

= simple_form_for [@competitor, @survey] |f|   - @survey.results.sort{ |a,b| b.points <=> a.points}.each |result|     = f.simple_fields_for result |r|       = r.input :selected, :label => result.name   = f.button :submit, :id => 'submit_survey' 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -