Hello all!
I have the following models:
Document belongs to a Task and to a Documentgroup and I want to select
the
Task that Document belongs to using a link where I can select the Task,
but
I also want to allow the user to select the Documentgroup using in the
same
way. How can I maintain the document state between these requests?
Here is the code:
Models:
class Document < ActiveRecord::Base
belongs_to :task
belongs_to :documentgroup
end
class Task < ActiveRecord::Base
end
class Documentgroup < ActiveRecord::Base
end
Views:
edit view:
<%= start_form_tag :action => “update” %>
<%= text_field_tag(“name”, @document.name) %>
<%= text_field_tag(“description”, @document.description) %>
<%= text_field_tag(“task”, @task.name) %>
<%= link_to “Select”, :action => ‘select_task’ %>
<%= text_field_tag(“documentgroup”, @documentgroup.name) %>
<%= link_to “Select”, :action => ‘select_documentgroup’ %>
<%= submit_tag “Change”, { ‘name’ => ‘change’} %>
<%= end_form_tag %>
select_task view:
<%= task.name %> | <%= link_to "Select", :action => "edit", :value => task.id %> |
select_documentgroup view:
<%= documentgroup.name %> | <%= link_to "Select", :action => "edit", :value => documentgroup.id %> |