Talks
Speakers
Events
Topics
Sign in
Home
Talks
Speakers
Events
Topics
Leaderboard
Use
Analytics
Sign in
Suggest modification to this talk
Title
Description
RailsConf 2019 - Learn to Make an API-Backed Model with Square’s Ruby SDK by Shannon Skipper _______________________________________________________________________________________________ Cloud 66 - Pain Free Rails Deployments Cloud 66 for Rails acts like your in-house DevOps team to build, deploy and maintain your Rails applications on any cloud or server. Get $100 Cloud 66 Free Credits with the code: RailsConf-19 ($100 Cloud 66 Free Credits, for the new user only, valid till 31st December 2019) Link to the website: https://cloud66.com/rails?utm_source=-&utm_medium=-&utm_campaign=RailsConf19 Link to sign up: https://app.cloud66.com/users/sign_in?utm_source=-&utm_medium=-&utm_campaign=RailsConf19 _______________________________________________________________________________________________ This is a sponsored talk by Square. Active Model is flexible enough to provide a model interface to APIs, not just databases! We’ll look at how to go beyond just including ActiveModel::Model to implement a rich set of Active Model features, including the recently-added Rails 5 Attributes API. How does this compare to Active Resource? What does it look like in your controller? We’ll answer these questions by exploring an example that wraps Square’s Customers API in a full-featured Rails model.
Date
Summarized using AI?
If this talk's summary was generated by AI, please check this box. A "Summarized using AI" badge will be displayed in the summary tab to indicate that the summary was generated using AI.
Show "Summarized using AI" badge on summary page
Summary
Markdown supported
The video titled "Learn to Make an API-Backed Model with Square’s Ruby SDK" presented by Shannon Skipper at RailsConf 2019 focuses on leveraging the ActiveModel module in Ruby on Rails to create flexible models that interact with APIs rather than traditional databases. The speaker begins by discussing Active Resource, which is limited to Rails JSON APIs, and introduces ActiveModel as a more adaptable solution for various API interactions. Key Points Discussed: - **Introduction to Active Resource**: Active Resource allows for the modeling of remote Rails applications but is constrained by its reliance on a standard Rails JSON API. This inflexibility has limited its integration into Rails core. - **Active Model Overview**: The speaker elaborates on how ActiveModel provides a model interface to APIs and not just databases. With the inclusion of ActiveModel::Model, features such as attribute assignment, validations, and error messages become available for non-database models. - **Attributes API**: The latest Rails versions include an Attributes API that allows for type coercion and easier data handling for Ruby classes. Custom attribute types can be created for more complex structures. - **Implementing Callbacks**: While ActiveModel doesn’t automatically implement callbacks, the speaker shows how to define lifecycle callbacks like save and update to mirror Active Record behavior. - **ActiveModel Dirty Tracking**: This feature tracks changes in the model's attributes with minimal code, allowing the user to understand what has changed before committing updates to the API. - **Serialization**: The speaker presents how models can be serialized to JSON easily, demonstrating how to convert models into hashes suitable for API interactions. - **Validations and I18n Support**: Standard Rails validations are applicable, allowing for easily manageable data integrity within API calls. Internationalization support is also covered, enhancing user-friendliness. - **Usage of Pretty Print and Inspect**: The speaker discusses implementing Pretty Print methods to enhance the visual representation of the model in rails console and IRB. - **Demonstration of Square API Integration**: A real-world example is demonstrated using Square’s Customers API, showcasing how to fetch, update, and delete customer records seamlessly. - **Conclusion regarding Active Resource**: The speaker concludes with guidance on when to use Active Resource versus ActiveModel, emphasizing the importance of CRUD operations and when a model is appropriately represented. **Takeaways**: Shannon Skipper encourages developers to explore the capabilities of ActiveModel for building robust, API-backed models. He highlights that while Active Resource has its place, ActiveModel provides greater flexibility and power for non-standard data sources, ultimately enriching the Rails development experience.
Suggest modifications
Cancel