What if we can increase page load the speed by not duplicating work in the server rendering process?
Category Archives: active record
Paginating Top Items – HOTWire HNPWA #3
If you look at the number of TopItems coming back from the API, you’ll see it’s much more than 30. How do you display all these items? Pagination! ActiveRecord has an offset method that tells the database where to start in the records it returns. If you don’t specify an offset, the database starts counting Continue reading “Paginating Top Items – HOTWire HNPWA #3”
Turbo Streaming Top Items – HOTWire HNPWA #2
Turbo Streaming is going to work best with ActiveRecord Models. The Hacker News model uses Item models, which can be stories, comments, jobs, polls, or poll options. In the first implementation, the Item was modeled to be as generic as the API dispensed. This time, stories and jobs will continue to be modeled as Item Continue reading “Turbo Streaming Top Items – HOTWire HNPWA #2”
How Do I Authorize Only the Creator of a Post to Update or Delete it?
Let’s say your Rails app has an ActiveRecord data type, Post, and you want to only authorize the creator of that Post, who is of type User, to update or delete the record. One way to prevent the wrong User from editing the Post is to keep track of the creator with a foreign key, Continue reading “How Do I Authorize Only the Creator of a Post to Update or Delete it?”