1
私は、ボランティアとイベントを管理するRails 3.2.3アプリケーションを持っています。私の意見の1つでは、私はボランティアイベントを破壊するためのリンクを作成しています。私はdata-remote = trueを使用しています。コントローラが正常に動作し、Railsはdestroy.js.erbをレンダリングしていると言いますが、ファイル内のスクリプトは呼び出されていません。私のスクリプトは、DIV要素を削除し、スパンの内容を更新しようとしています。ブラウザがdestroy.js.erbに応答しない
マイビューコード:
<%= link_to '', event, method: :delete, confirm: "Are you sure you want to delete this volunteer posting?", title: event.name, class: "icon-remove", remote: true%> </li>
私のコントローラコード: ...
respond_to :html, :js
def destroy
@volunteer_event = VolunteerEvent.find(params[:id])
@volunteer_event.destroy
respond_with(@volunteer_event)
end
マイdestroy.js.erb
ここでは詳細の一部です$("#hours_worked_total").html("<%= @volunteer_event.worker.account.total_hours_worked %>")
$("#volunteer_posting-<%[email protected]_event.id %>")
.fadeOut ->
$(this).remove()
これは、ビューに建てられた結果のHTMLです:これは、サーバーのログです
<ol class="events">
<div id="volunteer_posting-48">
<li><strong>9808</strong> worked on August 5, 2012 by <i>Louie Ferry</i> for a total of 5 hours.
<a href="/volunteer_events/48" class="icon-remove" data-confirm="Are you sure you want to delete this volunteer posting?" data-method="delete" data-remote="true" rel="nofollow" title="9808"></a> </li>
</div>
</ol>
:
Started DELETE "/volunteer_events/48" for 127.0.0.1 at 2012-05-08 11:17:50 -0400
...
Rendered volunteer_events/destroy.js.erb (2.7ms)
これは、ブラウザのリクエストとレスポンスです:
Response:
$("#hours_worked_total").html("0")
$("#volunteer_posting-48")
.fadeOut ->
$(this).remove()
Content-Type:text/javascript; charset=utf-8
私はそれがコーヒー気づいたが、何らかの理由で私はそれがJSファイル内で交換可能だと思いました。私の間違いと感謝ディラン。これは私の最初のレールアプリです。 – jplumey