2010-08-10 46 views
0

對於我的Ruby on Rails應用程序,我需要一次創建幾個LectureNote對象的可能性。我試着用這樣的觀點來做到這一點:將多個文件上傳到Ruby on Rails應用程序:第一個文件沒有上傳

<% form_for @lecture_note, :html => {:multipart => true} do %> 
    <%= hidden_field_tag 'thematic_block_id', params[:thematic_block_id] %> 
    <table> 

    <% (1..8).each do |i| %> 
    <tr> 
     <td><%= file_field "new_lecture_notes[][file]", 'datafile', :accept => 'application/pdf' %></td> 
     <td><%= text_field_tag "new_lecture_notes[][pages_per_sheet]", '', :size => 8 %></td> 
     <td><%= check_box_tag "new_lecture_notes[][color]", "1" %></td> 
     <td><%= select_date LectureNote.default_lecture_date, :order => [:day, :month, :year], :prefix => "new_lecture_notes[][lecture_date]" %></td> 
    </tr> 
    <% end %> 
    </table> 
    <%= submit_tag "Speichern" %> 
<% end %> 

然而,上載從未出現在params哈希表的第一個文件,第二個文件出現在這裏首先應該是,等的地方。如果我把text_field_tag放在file_field之前,它可以工作。任何想法爲什麼?

回答

0

我看了一下現在的Advanced Rails Recipes書籍,以及他們在一個表單中的多個模型示例,他們使用fields_for和text_field方法代替text_field_tag等。這樣做使所有事情都爲我工作,儘管我是仍然不確定爲什麼上述表格不起作用。

相關問題