Forum: Ruby on Rails Help with associations

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.
hlists (Guest)
on 2005-12-11 13:44
(Received via mailing list)
Hello all!

I have the following models:

Document belongs to a Task and to a Documentgroup and I want to select
Task that Document belongs to using a link where I can select the Task,
I also want to allow the user to select the Documentgroup using in the
way. How can I maintain the document state between these requests?

Here is the code:


class Document < ActiveRecord::Base
  belongs_to :task
  belongs_to :documentgroup

class Task < ActiveRecord::Base

class Documentgroup < ActiveRecord::Base


edit view:

<%= start_form_tag :action => "update" %>

<%= text_field_tag("name", %>
<%= text_field_tag("description", @document.description) %>

<%= text_field_tag("task", %>
<%= link_to "Select", :action => 'select_task' %>

<%= text_field_tag("documentgroup", %>
<%= link_to "Select", :action => 'select_documentgroup' %>

<%= submit_tag "Change", { 'name' => 'change'} %>

<%= end_form_tag %>

select_task view:


<% for task in @tasks %>
<tr><td><%= %></td><td><%= link_to "Select", :action =>
:value => %></td></tr>
<% end %>


select_documentgroup view:


<% for documentgroup in @documentgroups %>
<tr><td><%= %></td><td><%= link_to "Select", :action
"edit", :value => %></td></tr>
<% end %>

This topic is locked and can not be replied to.