Forum: Ruby on Rails has_many through select box in form

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
cjharrelson (Guest)
on 2008-11-19 20:15
(Received via mailing list)

I have searched the group and have not found any post that clarifies
thsi s=issue to me.  Please forgive me in advance if I missed

I have 3 models:

  has_many :citations, :dependent => :nullify
  has_many :violations, :through => :citations

  has_many :citations, :dependent => :nullify
  has_many :tickets, :through => :citations

  belongs_to :ticket
  belongs_to :violation

I am creating the edit a new views for the ticket and would like to be
able to relate N violations to the ticket.  My intent is to have one
select box with a control to add N more if desired.  The problem I am
running into is getting the select boxes created in a way such that
(1) existing items select the correct entry in the select box and (2)
when I post the form, Rails recognizes that I am trying to create N

I have tried following examples for a has_many relationship, but it is
not working the same.

Following is my current code:



<% form_for @ticket do |f| %>
  <%= render :partial => 'form', :locals => { :f => f }  %>
  <%= submit_tag 'Update Ticket' %>
<% end %>




<%= render :partial => 'violation', :collection =>
      :locals => { :f => f, :valid_violations => Violation.find
(:all) } %>




<%= f.collection_select :violations, valid_violations, :id, :name  %>


Should I be referencing the citation instead of the violation?  I
cannot figure out where this needs to go.  Please help.
This topic is locked and can not be replied to.