Forum: Ruby on Rails Formatting form tags for children of parrent data?

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.
Lance S. (Guest)
on 2006-04-07 22:01
This my first Rails project.

All my previous work was done it Perl, so I may be missing the
Ruby/Rails obvious here.

The site I'm working on needs to display archived programs.
Some of the programs have multiple versions, all belonging to the same
As such, I've set-up an extra_files table related to the archive list.

Displaying the extra files was trivial. However, when I went to edit the
edit.rhtml file, I had no idea how to format the text input fields so
that they would be automaticly picked-up and placed with the parrent.

Here's what I have:

archives table:
id program_name file_location etc...

archives model:
class Archive < ActiveRecord::Base
	belongs_to :category
	has_many :extra_file

extra_files table:
id archive_id name location

extra_files model:
class ExtraFile < ActiveRecord::Base
	belongs_to :archive

list.rhtml Relivent section:
<% @programs.each do |program| -%>
<td><%= link_to program.program_name, program.file_location %>
<% program.extra_file.each do |file| -%>
<br><%= link_to, file.location %>
<% end -%></td>
<td><%= %></td>
<td><%= program.reference %></td>
<td><%= program.format %></td>
<td><%= program.description %></td>

Now How to display the extra_files name and location in the edit.rhtml,
so they can be edited, and  returned to the proper place in the database
is where I'm stuck...

I'm presuming the extra_file id would need to be associated with the
name and location fields somehow...

Here's my edit.rhtml as it currently stands:
  <title>Edit Program Listing</title>
 <h1>Edit Program Listing</h1>

 <form action="../update/<%= %>" method="POST"">
  <input id="archive_id" name="archive[id]" size="30"
         type="hidden" value="<%= %>" />
  <input id="program_name" name="archive[program_name]" size="30"
         type="text" value="<%= @program.program_name %>" />
  <input id="program_author" name="archive[author]"
         size="30" type="text"
         value="<%= %>" />
  <input id="program_format" name="archive[format]"
         size="30" type="text"
         value="<%= @program.format %>" />
  <input id="program_reference" name="archive[reference]"
         size="30" type="text"
         value="<%= @program.reference %>" />
  <p><b>Release Date</b><br>
  <input id="program_release_date" name="archive[release_date]"
         size="30" type="text"
         value="<%= @program.release_date %>" />
  <textarea id="program_description" name="archive[description]"
         cols="40" rows="20" wrap="virtual"
><%= @program.description %></textarea>
  <p><b>Misc (extended Description)</b><br>
  <textarea id="program_misc" name="archive[misc]"
         cols="40" rows="20" wrap="virtual"
><%= @program.misc %></textarea>
  <select id="program_baud" name="archive[baud]">
  <% ['2000','300','2000 BlueRam'].each do |baud| -%>
  <option <%= 'selected' if @program.baud == baud %>><%= baud
  <% end -%>
  <p><b>Archival Status</b><br>
  <input id="program_arc_status" name="archive[arc_status]"
         size="30" type="text"
         value="<%= @program.arc_status %>" />
  <p><b>File Location<b><br>
  <input id="program_file_location" name="archive[file_location]"
         size="30" type="text"
         value="<%= @program.file_location %>" />
  <p><b>Extra Ram</b><br>
  Yes <input name="archive[ext_ram]"
         type="radio" value="1"
         <%= 'checked' if @program.ext_ram == 1 %> />
  No <input name="archive[ext_ram]"
        type="radio" value="0"
        <%= 'checked' if @program.ext_ram == 0 %> />


  <select name="archive[category_id]">
   <% @categories.each do |category| -%>
       <option value="<%= %>" <%= 'selected' if
== @program.category_id %>><%= %></option>
   <% end -%>

<input type="submit" value="Update" />

 <a href="/program_downloads/Archive/archive/show/<%= %>">
Show </a> |
  <%= link_to "Back", :action => "list" %>


I'm looking to add the list of existing extra files after the Category

I started with this:
  <p><b>Extra Files</b><br>

  <% program.extra_file.each do |file| -%>
  <input id="...

... is where I realised I had NO concept how to ensure the data would
stay together properly...

Lance F. Squire
Lance S. (Guest)
on 2006-04-08 00:14
After much hacking I've got this:
  <p><b>Extra Files</b><br>

  <% @program.extra_file.each do |file| -%>
  Name: <input name="archive[extra_file[<%= %>]][name]"
         value="<%= %>" />
  Location: <input name="archive[extra_file[<%= %>]][location]"
	value="<%= file.location %>" /><br>
  <% end -%>

Which looks promissing in the paramiters view on the error page, but
still dosen't work...

"extra_file[2]"=>{"name"=>"test Extra files2+", "location"=>"#"},
"extra_file[1]"=>{"name"=>"test Extra files1+", "location"=>"#"},
This topic is locked and can not be replied to.