私はレール3.1を使用しています。私はajaxで検索フォームを作成しています。私はすでにポストメソッドを使ってフォームを作成しています。AjaxのクエリとRuby on Rails
<%= form_tag(root_path, :method => "post",:id =>"formid") do %>
<%= label_tag(:number1, "El que quiero") %>
<%= text_field_tag :quiero, nil, :class => 'drug_autocomplete' %>
<%= hidden_field_tag :number1 %>
<%= label_tag(:number1, "El modelo que tengo") %>
<%= text_field_tag :tengo, nil, :class => 'drug_autocomplete' %>
<%= hidden_field_tag :number2 %>
<%= label_tag(:size1, "Talla de el que tengo") %>
<%= text_field_tag :size1%>
<%= submit_tag("Do it!") %>
<% end %>
私はsubmitイベントを処理するために何かを書いていました。
jQuery.ajaxSetup({
'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript")}
})
jQuery.fn.submitWithAjax = function() {
this.submit(function() {
$.post(this.action, $(this).serialize(), null, "script");
return false;
})
return this;
};
$(document).ready(function() {
$("#form_id").submitWithAjax();
})
コントローラは、フォームのパラメータを受け取り、このようにデータベースにクエリを作成します。
@itemsok = Contribution.where("first_item_id = ?",item1.id).where("second_item_id = ?",item2.id).where("second_item_grade = ?",size1
そして、私が達成したいどのような同じビュー
<%if not @itemsok.nil?
@itemsok.each do |searches|
%>
<table>
<tr>
<td style="width:100px;"><%= searches.first_item.description %> </td>
<td style="width:150px; font-size:30px;"><%= searches.first_item_grade %> </td>
<td style="width:150px;"><%= searches.second_item.description %> </td>
<td style="width:150px; font-size:30px;"><%= searches.second_item_grade %> </td>
<td style="width:150px; font-size:18px;"><a href="<%= contribution_path(searches.id) %>">Show</a> </td>
</tr>
</table>
にデシベルで見つかったパラメータを返すデータベースにクエリを作成すると同じですが、Ajaxを使ってページ内にありませんのでリロード必要です。 最初の質問ですが、フォームのデータをjavascriptのどこかで処理する必要があります。 2番目の質問、戻ってきたときにデータを処理するにはどうすればいいですか?
私はAjaxでRailsで完全に失われているので、助けてください。 ありがとうございます。 私のひどい英語のために申し訳ありません。