0

(たくさん)見回した後、この件に関する多数の投稿を掘り下げましたが、この問題は主にしばらく前(変更が発生したとき)に対処されたようで、現在の状況とほとんど一致しないため、本当に混乱しています.

そのため、Rails 2.1 アプリを 3.2 に更新しようとしていますが、非推奨の link_to_remote 関数に遭遇しました。link_to :remote => true に置き換えられていることに気付きましたが、それは私の問題に実際には答えません。

私が取り組んでいるアプリは、次のようなページ内レンダリングを行うために多くのプロトタイプ マジックを使用しています。

/acl/main.html.erb で:

<table width=95%>
<tr><td align=center valign=top width=30%> <!-- Employees List -->

    <%= render(:partial => "employee_list") %>


</td><td align=center valign=top> <!-- Roles & Privileges List -->

    <div id='roles' style="border: 1px solid black; background-color: #ddd;">
    <% if @employee.blank? %>
        <h4>Select employee to see access details.</h4>
    <% elsif @show_uploads %>
        <%= render :partial => 'employee_uploads' %>
    <% else %>
        <%= render :partial => 'employee_edit' %>
    <% end %>
    </div>

</td></tr>

そして、acl/_employee_list.html.erb で:

<span class="simple">
<table class="production_list">

<tr>
    <th colspan=10>
    Employees &nbsp 
    <% if @show_all %>
        <%= link_to 'Show only active', {:action => "main"} %>
    <% else %>
        <%= link_to 'Show inactive', {:action => "main", :show_all => 1} %>
    <% end %>
    &nbsp 
    <%= link_to_remote  'Create',
                { :url => {:action => "create_employee"}, :update => 'roles' } %>

    </th>
</tr>
<tr class="default_header_row">
    <th width=50 class="default_header_cell small_08">Initials</th>
    <th width=190 class="default_header_cell small_08">Name</th>
    <th width=90 class="default_header_cell small_08">Access</th>
</tr>

<%= render(:partial => "employee_item", :collection => @employees) %>

</table> 
</span>

acl/_employee_create.html.erb は単なる入力の長いテーブルであり、明らかにページの #post div に挿入されます。

それで、私の質問は、これを Rails 3.2 の UJS で実行するにはどうすればよいですか?

gemfile にデフォルトの jquery-rails がありますが、ajax 呼び出しを処理する場所が見つからないようです。正直なところ、これをどのように修正すればよいかわかりません (特により一般的な方法)。アプリケーションはあらゆる場所でこの動作を行っているため、以前の動作を模倣する何らかの解決策を考え出す必要があります。

4

2 に答える 2

0

/acl/main.html.erb: (routes ファイルに employees_path があると仮定します)

<%= link_to employees_path, remote:true %>

/acl/employees/index.js.erb:

<%= for employee in @employees %>
  $('table tbody').append(<%= j raw render('employee', employee:employee))
<% end %>

于 2013-08-02T13:56:44.873 に答える