Skip to content

Commit

Permalink
search works
Browse files Browse the repository at this point in the history
  • Loading branch information
happypeter committed Sep 28, 2014
1 parent 99043a1 commit c2814a6
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
8 changes: 8 additions & 0 deletions esdemo/app/assets/stylesheets/users.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,11 @@
.new-user {
margin-top: 50px;
}


.search-result-page {
.back {
margin-top: 30px;
display: block;
}
}
11 changes: 11 additions & 0 deletions esdemo/app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ def destroy
redirect_to :root
end

def search
@users = User.search(
query: {
multi_match: {
query: params[:q].to_s,
fields: ['name', 'intro']
}
}
).records
end

private
def user_params
params.require(:user).permit(:intro, :name)
Expand Down
2 changes: 2 additions & 0 deletions esdemo/app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
class User < ActiveRecord::Base
include Elasticsearch::Model
include Elasticsearch::Model::Callbacks
end
19 changes: 19 additions & 0 deletions esdemo/app/views/users/search.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<div class="search-result-page">
<table>
<tr>
<th class="name">Name</th>
<th class="intro">Intro</th>
</tr>

<% @users.each do |u| %>
<tr class="list">
<td class="name"><%= u.name %></td>
<td class="intro"><%= u.intro %></td>
</tr>
<% end %>
</table>

<%= link_to root_path, class: "back" do %>
<i class="fa fa-arrow-left"> Back</i>
<% end %>
</div>

0 comments on commit c2814a6

Please sign in to comment.