Created
July 26, 2013 02:06
-
-
Save poc7667/6085495 to your computer and use it in GitHub Desktop.
Search form with ajax not worked ?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ul> | |
<% if [email protected]? %> | |
<% @results.each do |result| %> | |
<li> | |
<%= result %> | |
</li> | |
<% end %> | |
<% else %> | |
<%= @results.inspect %> | |
<%= Time.now %> | |
<% end %> | |
</ul> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('#search').html("<%= escape_javascript(render :partial => 'results') %>"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[#<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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def self.search(key) | |
if key | |
find(:all, :conditions => ['translate_str LIKE ?', "%#{key}%"]) | |
else | |
find(:all) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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