#12 update the serialzier of search result

This commit is contained in:
2015-12-08 22:55:10 +08:00
parent 56fa8ef7ea
commit 4383339ddf
4 changed files with 11 additions and 3 deletions
+2 -2
View File
@@ -4,9 +4,9 @@ class Api::V1::SearchController < ApplicationController
def index
#.pluck(:id, :title, :url, :type, :good_format, :summary)
posts = Post.where('title LIKE ?',"%#{params[:keywords]}%").limit(5)
posts = Post.select(Post.json_attrs).where('title LIKE ?',"%#{params[:keywords]}%").limit(5)
#.pluck(:id, :email, :name, :avatar)
users = User.where('name LIKE ?', "%#{params[:keywords]}%").limit(5)
users = User.select(User.json_attrs).where('name LIKE ?', "%#{params[:keywords]}%").limit(5)
render json: {
posts: posts,
users: users
+5
View File
@@ -19,4 +19,9 @@ class Post < ActiveRecord::Base
def first_sharer
share_instances.first.user_name
end
def self.json_attrs
[:id, :url, :title, :type, :summary]
end
end
+4
View File
@@ -23,6 +23,10 @@ class User < ActiveRecord::Base
acts_as_paranoid
def self.json_attrs
[:id, :email, :name]
end
def followers
user_ids = FollowRelation.where(star_id: self.id).pluck(:user_id)
User.where(id: user_ids)
-1
View File
@@ -1,4 +1,3 @@
class EMSourceSerializer < ActiveModel::Serializer
include Rails.application.routes.url_helpers