Hallo Werner & Liste,

tja, es lag am Code in der view:

>>          <%= check_box_tag "service[metrics][]", metric.id, 
>> @service.metrics.include?(metric) %>
muss heissen:

        <%= check_box_tag "service[metric_ids][]", metric.id, 
@service.metrics.include?(metric) %>

was ja auch irgendwie Sinn ergibt, nachdem ich ja die IDs der jeweiligen Metric 
in den Parameter-Hash schicke (metric.id)

Der Railscast ist übrigens #17 - allerdings geht es da explizit um hbtm (im 
Gegensatz zu join tables mit :through)

Schönen Abend, Jürgen

On Apr 13, 2010, at 10:16 PM, Werner Laude wrote:

> 
> Am 13.04.2010 um 16:33 schrieb Jürgen Walter:
> 
> hallo Jürgen.
> 
> Wo der Fehler liegt..weiß ich nicht
> 
> Ich habe das mit einer  join tabelle gelöst
> 
> CREATE TABLE `seminars_therapists` (
>  `seminar_id` int(11) NOT NULL DEFAULT '0',
>  `therapist_id` int(11) NOT NULL DEFAULT '0',
>  PRIMARY KEY (`seminar_id`,`therapist_id`)
> ) ENGINE=InnoDB DEFAULT CHARSET=utf8
> 
> 
> has_and_belongs_to_many :therapists
> has_and_belongs_to_many :seminars
> 
> 
> def show
>    @seminar = Seminar.find(params[:id])
>    @therapists = @seminar.therapists # therapeuten aus der join tabelle
> 
> 
> new
>  <%[email protected]_groups_of(4, false) do |t_rows|%>
> 
>  <%for t in t_rows%>
>  <%= check_box_tag "seminar[therapist_ids][]", t.id, 
> @seminar.therapists.include?(t) %> <%=t.name%>
>  <% end %>
> 
>  <% end %>
> 
> Es gibt auch eine Video von Ryan B... weiß aber gerade nicht welche Nummer
> 
> Gruß
> 
> 
> 
>> Hallo Liste,
>> 
>> habe hier folgende Konstellation:
>> 
>> service.rb
>> has_many :definitions
>> has_many :metrics, :through => :definitions
>> 
>> metric.rb
>> has_many :definitions
>> has_many :services, :through => :definitions
>> 
>> definition.rb
>> belongs_to :metric
>> belongs_to: service
>> 
>> 
>> In der edit/new view für einen Service möchte ich gerne eine liste von 
>> check_boxes, so dass ich auswählen kann, welche metrics zum Service gehören.
>> 
>> Bisher habe ich es so versucht:
>> 
>> 
>>      <% for metric in Metric.all %>
>>          <%= check_box_tag "service[metrics][]", metric.id, 
>> @service.metrics.include?(metric) %>
>>          <%=h metric.label %><br />
>>        <% end %>
>> 
>> Aber ich bekomme folgende Fehlermeldung, nachdem ich das (edit) Formular 
>> abgeschickt habe:
>> 
>> Processing ServicesController#update (for 127.0.0.1 at 2010-04-13 16:13:28) 
>> [PUT]
>> Parameters: {"commit"=>"Create", "service"=>{"name"=>"AAA", "label"=>"aaa", 
>> "metrics"=>["3"]}, "id"=>"1"}
>> Service Load (0.2ms)   SELECT * FROM "services" WHERE ("services"."id" = 1) 
>> 
>> ActiveRecord::AssociationTypeMismatch (Metric(#2182532020) expected, got 
>> String(#2148312060)):
>> app/controllers/services_controller.rb:63
>> app/controllers/services_controller.rb:62:in `update'
>> 
>> 
>> Habt ihr eine Idee? Gruss, Jürgen
>> 
>> 
>> _______________________________________________
>> rubyonrails-ug mailing list
>> [email protected]
>> http://mailman.headflash.com/listinfo/rubyonrails-ug
>> 
> 
> Werner Laude
> [email protected]
> 
> 
> 
> _______________________________________________
> rubyonrails-ug mailing list
> [email protected]
> http://mailman.headflash.com/listinfo/rubyonrails-ug

_______________________________________________
rubyonrails-ug mailing list
[email protected]
http://mailman.headflash.com/listinfo/rubyonrails-ug

Antwort per Email an