Skip to content

Instantly share code, notes, and snippets.

@poc7667
Created July 26, 2013 02:06
Show Gist options
  • Save poc7667/6085495 to your computer and use it in GitHub Desktop.
Save poc7667/6085495 to your computer and use it in GitHub Desktop.
Search form with ajax not worked ?
<ul>
<% if [email protected]? %>
<% @results.each do |result| %>
<li>
<%= result %>
</li>
<% end %>
<% else %>
<%= @results.inspect %>
<%= Time.now %>
<% end %>
</ul>
$('#search').html("<%= escape_javascript(render :partial => 'results') %>");
<%= form_tag translate_search_path, :method => :get,
:remote => true, :'data-update-target' => 'search' do %>
<%= text_field_tag :search %>
<%= submit_tag 'Search' %>
<% end %>
<div id="search">
<%= render 'search' %>
<%= render :partial => 'search' %>
</div>
[#<Translate id: 1544, translate_str: "yellow", EN: "Yellow", DE: "Gelb", ES: "Amarillo", FR: "Jaune", IT: "Giallo", JP: "黄色", PT: "Amarelo", CN: "黄色", TW: "黃色", created_at: "2013-07-24 10:27:32", updated_at: "2013-07-24 10:27:32">]
Started GET "/translate/search?utf8=%E2%9C%93&search=yellow&commit=Search" for 172.16.38.42 at 2013-07-26 10:03:34 +0800
Processing by TranslatesController#search as JS
Parameters: {"utf8"=>"✓", "search"=>"yellow", "commit"=>"Search"}
Translate Load (2.2ms) SELECT "translates".* FROM "translates" WHERE (translate_str LIKE '%yellow%')
Rendered translates/search.html.erb (0.7ms)
Completed 200 OK in 8ms (Views: 3.2ms | ActiveRecord: 2.2ms)
def self.search(key)
if key
find(:all, :conditions => ['translate_str LIKE ?', "%#{key}%"])
else
find(:all)
end
end
def search
@results = Translate.search(params[:search])
respond_to do |format|
format.js
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment