Question about collection_check_box

Hi there,

i want to use collection_check_boxes (in rails 4) but i am a little bit
stuck… okay, first things first:

i have 2 models:


class Supervisioncategory < ActiveRecord::Base
has_many :phonenotes
end

and


class Phonenote < ActiveRecord::Base
belongs_to :employee
belongs_to :supervisioncategory
belongs_to :trainingcategory
end

and i want to use collection_check_box for the categories


<%= f.label :supervision %>
<%= collection_check_boxes :phonenote, :supervision_ids, @supervisions, :id, :name %>
----------------

shows all the categories i want, i can check them, i made the
“:supervision_ids” accessible. But then…
nothing happend? I think my problem is at the typ of the
“:supervision_ids”… integer won’t work, string won’t work. So… can
someone help me with this Problem?

Regards,

Ronny

On Dec 3, 2013, at 12:18 PM, Ronny F. wrote:


nothing happend? I think my problem is at the typ of the “:supervision_ids”…
integer won’t work, string won’t work. So… can someone help me with this
Problem?
View source as generated by Rails in your browser, and see what these
checkboxes look like in HTML. That’s where I would start debugging this.
My guess is that you need these to be supervisioncategory_ids, since
that’s what the b/t is saying the model is named. But without looking at
the HTML, we won’t know if your checkboxes are properly named to post as
an array back to your controller.

Walter

Am 2013-12-03 18:42, schrieb Walter Lee D.:

View source as generated by Rails in your browser, and see what these
checkboxes look like in HTML. That’s where I would start debugging
this. My guess is that you need these to be supervisioncategory_ids,
since that’s what the b/t is saying the model is named. But without
looking at the HTML, we won’t know if your checkboxes are properly
named to post as an array back to your controller.

Walter

Here you go:

Supervision
TG P Fahrdienst

Regards

On Dec 3, 2013, at 12:49 PM, Ronny F. wrote:

Here you go:

Regards

Okay, that looks right, as far as it goes. Now what happens in your
console if you find a phonenote, and ask for its supervisions?

p = Phonenote.first
p.supervisions

error, or array?

Walter

Am 2013-12-03 19:26, schrieb Walter Lee D.:

Okay, that looks right, as far as it goes. Now what happens in your
console if you find a phonenote, and ask for its supervisions?

p = Phonenote.first
p.supervisions

error, or array?

2.0.0-p353 :002 > p.supervisions
NoMethodError: undefined method `supervisions’ for
#Phonenote:0xb042698

Ronny

Am 2013-12-03 19:46, schrieb Ronny F.:

2.0.0-p353 :002 > p.supervisions
NoMethodError: undefined method `supervisions’ for
#Phonenote:0xb042698

Ronny

2.0.0-p353 :002 > p.supervisions
NoMethodError: undefined method `supervisions’ for
#Phonenote:0xb042698

2.0.0-p353 :003 > p.supervisioncategories
NoMethodError: undefined method `supervisioncategories’ for
#Phonenote:0xb042698

2.0.0-p353 :004 > p.supervisioncategory_id
=> nil
2.0.0-p353 :005 >

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs