2

1 つのフォームを使用して複数のレコードを編集しようとしているので、ユーザーはいくつかのレコードを編集し、個々のレコードの後ではなく、最後に送信を押すことができます。現在のコードを投稿しましたが、次のエラーが発生します。

undefined method `connection_connection_path'

コントローラ

def show
  @customer = Customer.find(params[:id])
  @connection = @customer.connections
  respond_to do |format|
    format.html # show.html.erb
    format.json { render json: @customer }
  end
end

意見

<table class="table">
    <thead>
        <th>Interface</th>
        <th>Device</th>
        <th>Speed</th>
        <th>Site</th>
        <th>Capable</th>
        <th>Notes</th>

    </thead>
    <%= form_for(@connection) do |f| %>
    <% @connection.each do |l| %>
    <tr>
        <td><%= l.interface %></td>
        <td><%= l.device %></td>
        <td><%= l.speed %></td>
        <td><%= l.site.name%> </td>
        <td><%= f.check_box :check %></td>
        <td><%= f.text_field :notes %></td>

    </tr>
    <% end %>
            <tr><%= f.submit %></tr>
</table>
<% end %>

ルート

resources :connections


resources :sites


resources :customer_sites


resources :customers

root :to => "customers#index"
4

1 に答える 1

0

送信ボタンはどこにありますか?? ショーで行うべきではありません。コントローラーで新しいメソッドを作成し、複数の編集機能を実行する可能性があります。

基本的な概念は、チェックがある場合、オブジェクトの配列をメソッドに渡し、それらを 1 つずつ更新する必要があるということです。または、JS を使用してそれを行うこともできます。

このレールキャストを参照してください http://railscasts.com/episodes/165-edit-multiple

そしてこのstackoverflow Rails 3 Edit Multiple Records in a Single Form

これらのリソースは Google で簡単に入手できます :D それでも問題がある場合は、ここに来てもう一度質問してください

于 2013-05-23T16:11:14.437 に答える