Answer the question
In order to leave comments, you need to log in
How can I implement filters on the Rails Api?
How can I make sure that certain filters are set on the rails and the client has already received filtered data from the server in advance (well, for example, the filter: name != null ). If this requires a serializer, I also use it.
def index
posts = paginate Post.all.order(:name), per_page: 10
render json: { data: posts.as_json, meta: { total: Post.count } }
end
Answer the question
In order to leave comments, you need to log in
If I understand correctly, then ActiveRecord has a where method specifically for this purpose.
Post.where.not(name: nil).order(:name)
But it is not clear why to store posts with empty names in the database at all.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question