Files
libr-2/app/controllers/api/v1/search_controller.rb

17 lines
514 B
Ruby

class Api::V1::SearchController < ApplicationController
skip_before_action :authenticate_user_from_token
def index
#.pluck(:id, :title, :url, :type, :good_format, :summary)
posts = Post.select(Post.json_attrs).where('title LIKE ?',"%#{params[:keywords]}%").limit(5)
#.pluck(:id, :email, :name, :avatar)
users = User.select(User.json_attrs).where('name LIKE ?', "%#{params[:keywords]}%").limit(5)
render json: {
posts: posts,
users: users
}
end
end