mirror of
https://github.com/wahyd4/libr-2.git
synced 2026-08-09 05:15:53 +10:00
#12 update the serialzier of search result
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,4 +1,3 @@
|
||||
|
||||
class EMSourceSerializer < ActiveModel::Serializer
|
||||
include Rails.application.routes.url_helpers
|
||||
|
||||
|
||||
Reference in New Issue
Block a user