Rails 6 API Tutorial - API Pagination p.15

preview_player
Показать описание
In this video series we will build a Rails API from scratch. Backend APIs are useful for serving data to frontend applications, mobile apps or other backend services.

This video covers:
00:00 - What is pagination and why do we need it
00:50 - Writing a test to describe how we want pagination to work
02:35 - Adding limit and offset to our ActiveRecord Books query
03:58 - Adding a test for offset
05:41 - Adding a maximum limit of 100 to prevent users requesting too many records
06:18 - Writing a test to verify that users cannot request too many records
07:54 - Adding an RSpec 'expect to receive' model expectation
09:46 - Implementing max limit logic using Ruby's min method
13:10 - Tidy up the limit method using a named constant
14:16 - Move the max limit test into a controller spec

Рекомендации по теме
Комментарии
Автор

Dude, your tutorial without a doubt beats up most of the paid tutorials out there

aymanhassan
Автор

Best series I have loved! Its just polishing me up. Thank you Tom.

nakittocatherine
Автор

This is the best API series, I've learned so much!! Thanks Tom!

artofthesystem
Автор

Thanks man, this series helped me a lot ❤

ahmedmustafa
Автор

I am so grateful for this video, thank you! Please make a course for RSpec in depth 🙏

michiharuono
Автор

I totally forgot pagination was so easy to do without a gem in Rails. I think if I had a view I'd still reach for kaminari for sanity, but this is neato!

MikeRogers
Автор

Another excellent video. But I can not make the limit test work. Although my API returns the MAX_PAGINATION_VALUE of posts the test gives an error. Is there any other way to test if the max limit is returned? Thanks

nickharalampopoulos
Автор

Hi @tom,

I have a very weird thing on when I am following your tutorial.

As per your last comment on a previous video, I noticed that use _transactional_fixtures is set to true by default in the rails_helper file in the spec folder.



Diff:
@@ -1, 5 +1, 5 @@
"author_age" => 48,
"author_name" => "Andy Weir",
-"id" => 1,
+"id" => 58,
"title" => "The martian",

If you noticed the book_id that's coming out is 58, whereas it should be 1. Would be great if you think you can help out. :)

nikgoy
Автор

Hi..this series is really helpful.but i am getting error with response_body

ishitaghosh
Автор

I have a question, how do i paginate with filtering, for example, i want to paginate all my results that are the newest or the ones with the most votes.

ripndipp
Автор

this doesn't seem to work (the pagination test over 100 limit) on rails 7, any reason why?

ctrlaltcal