0

私の見解では、私は次のことを行います。

<table border="1">
 <tr>
    <th>Question</th>
    <th>Counter</th>
    <th>Lastsent</th>
    <th>Email</th>
  </tr>
<% @email_stats.each do |email_stat| %>
<% post = Post.find(email_stat.postId) %>
  <% if post.posttype == 'Question' %>
  <tr>
    <td><%= post.question %></td>
    <td><%=  email_stat.counter%></td>
    <td><%= email_stat.lastsent %></t>
    <td><%=  text_field_tag 'email', email_stat.email%></td>
  </tr>
  <%  end %>
 </table>

これが私が持っているものです。一部のオブジェクトでは、電子メールが「空白」になるため、テーブル内のすべてのレコードを表示し、モデレーターが電子メールを入力して保存をクリックして保存できるようにします。

使用form_forしましたが、1つのオブジェクトのみを保存するために使用されています。

保存のためにアレイをサーバーに送り返す最良の方法は何ですか?

4

2 に答える 2

0

form_for の代わりに form_tag を使用すると、予期される動作を実現できます。例

<%= form_tag :url => , :html => {:id=> , :method => , :class => ""} do %>
  <% text_field_tag <id>, <default_value>, :name=>"post[question]" %>
  <% text_field_tag <id>, <default_value>, :name=>"email_stat[counter]" %>
  <% text_field_tag <id>, <default_value>, :name=>"email_stat[last_sent]" %>
  <% text_field_tag <id>, <default_value>, :name=>"email_stat[email]" %>
  <%= submit_tag 'save' %>
<% end %>

パラメータは、次のようなハッシュにうまくグループ化されます

{'post' => {'question' => 'xxx' }, 'email_stat' => {'counter' => 'xxx' , 'last_sent' =>  'xxx', 'email' => 'xxx'}} 

これを解析して両方のモデルを更新できます。必要なことは、text_field に適切な名前を付けることだけです。

于 2012-11-01T13:54:29.673 に答える
0

jqueryを使用してテーブルからデータをシリアル化し、データをサーバー側に戻すために、ajaxを使用できると思います。したがって、配列を保存できます。

于 2012-11-01T05:35:44.783 に答える