私はずっと検索してきましたが、なぜこれが機能しないのかわかりません。
非常に基本的な ajax アクションをテストしようとしています。ここに私のコードがあります:
コントローラ:
def commit
respond_to do |format|
format.html { redirect_to :action => "index" } # see note 1
format.js { render :layout => false } # see note 2
format.js { render :nothing => true }
end
end
意見:
<%= link_to "commit", :action => "commit", :remote => true %>
<%= form_tag( :action => "commit", :remote => true, :method => :post) do %>
<%= submit_tag "commit" %>
<% end %>
<div id='message'></div>
commit.js.erb
console.log('committed');
$('#message').html("committed");
問題は、コミット メソッドに到達することですが、ページがリロードされ、remote=>true のポイントが無効になります。また、commit.js が呼び出されることはありませんでした。
注 1: この行を除外すると、空白ページが /commit に取得されます。それを含めると、ページがリロードされるだけです
注2:他のSO投稿で提案されたこれらのアプローチの両方を試しました
注3:link_toとform_tagの両方を使用して試しました
誰でも助けることができますか?ありがとう!