{"id":15981,"date":"2024-06-28T13:15:46","date_gmt":"2024-06-28T20:15:46","guid":{"rendered":"https:\/\/www.couchbase.com\/blog\/?p=15981"},"modified":"2025-06-13T21:11:02","modified_gmt":"2025-06-14T04:11:02","slug":"couchbase-rails-guide-adaptive-data","status":"publish","type":"post","link":"https:\/\/www.couchbase.com\/blog\/couchbase-rails-guide-adaptive-data\/","title":{"rendered":"Couchbase on Rails: A Guide to Introducing Dynamic and Adaptive Data to Your Application"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">Ruby on Rails is often the framework of choice for getting new projects off the ground. The speed of development and iteration is in many ways unparalleled. As such, perhaps you want to use Rails as the framework for your application that requires a lot of flexibility in data and has a fluid structure. Maybe you are building an Internet of Things application or a Content Management System that must handle all sorts of data. The traditional database solutions for Rails will just not cut it. What do you do?<\/span><\/p>\n<p><span style=\"font-weight: 400;\">In this guide, you will discover the considerations and steps to utilizing Couchbase as your database fully integrated into your Rails application. The decision to build with Couchbase introduces not only technical implementation changes, but also conceptual changes in the way you approach your data. Let\u2019s dive into them.<\/span><\/p>\n<hr \/>\n<p><i><span style=\"font-weight: 400;\">tl;dr Interested in just seeing code? Check out a real world fully built example app demonstrating all CRUD actions with Ruby on Rails and the Couchbase Ruby ORM on <\/span><\/i><a href=\"https:\/\/github.com\/hummusonrails\/realworld-couchbase-ruby-orm\/tree\/main\"><i><span style=\"font-weight: 400;\">GitHub<\/span><\/i><\/a><i><span style=\"font-weight: 400;\">.<\/span><\/i><\/p>\n<hr \/>\n<h2>Document model vs Relational model<\/h2>\n<p><span style=\"font-weight: 400;\">In Rails, you&#8217;re accustomed to working with a relational model, typically using ActiveRecord. Data is organized in tables with rows and columns, and relationships between entities are defined using foreign keys. Couchbase, on the other hand, uses a document model, where data is stored in JSON documents.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The document model allows for more flexibility in data structures. For example, you now have the ability to store nested data directly into the same document of the parent data. This means that if you are building a blogging platform, comments on articles can be appended directly into the JSON document of each article, instead of associating comments to articles by the comment ID. When you would choose to use this ability or not depends on access patterns and performance considerations that you must give thought to as you design your application.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The difference in data will look like the following examples.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Embedded comments:<\/span><\/p>\n<pre class=\"nums:false lang:js decode:true \">{\r\n\u00a0\u00a0\"title\": \"My Article\",\r\n\u00a0\u00a0\"content\": \"This is the content of the article...\",\r\n\u00a0\u00a0\"comments\": [\r\n\u00a0\u00a0\u00a0\u00a0{\"author\": \"User1\", \"text\": \"Great article!\"},\r\n\u00a0\u00a0\u00a0\u00a0{\"author\": \"User2\", \"text\": \"Thanks for the info.\"}\r\n\u00a0\u00a0]\r\n}<\/pre>\n<p><span style=\"font-weight: 400;\">Whereas, the traditional model that most Rails developers are familiar with looks like this:<\/span><\/p>\n<pre class=\"nums:false lang:js decode:true\">{\r\n\u00a0\u00a0\"title\": \"My Article\",\r\n\u00a0\u00a0\"content\": \"This is the content of the article...\",\r\n\u00a0\u00a0\"comment_ids\": [\"comment1\", \"comment2\"]\r\n}\r\n<\/pre>\n<p>When deciding how to model your data in Couchbase, it&#8217;s essential to consider how your application will read and write data. If you choose to embed comments within the article document, you can achieve faster read operations since all the data is contained in a single document. This approach is beneficial when you need to retrieve an article along with all its comments quickly. However, the downside is that any updates to the article or its comments require rewriting the entire document. This can be inefficient, especially if the document is large or if updates are frequent. Therefore, embedding comments is suitable for scenarios where comments are rarely updated independently of the article, and read performance is crucial.<\/p>\n<p><span style=\"font-weight: 400;\">On the other hand, referencing comments by their IDs allows for more granular updates. Each comment can be updated independently of the article, making write operations more efficient. However, this approach may result in slower read operations since retrieving an article with all its comments requires multiple document fetches. This pattern is advantageous when comments are frequently updated or when the overall document size needs to be kept smaller for performance reasons.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Understanding these trade-offs helps you make informed decisions on how to structure your data in your application. By carefully considering your application&#8217;s read and write patterns, you can optimize performance and ensure efficient data management.<\/span><\/p>\n<h2>Rails caching helps reduces any performance trade-offs<\/h2>\n<p><span style=\"font-weight: 400;\">There is one method that you can utilize in your Rails application to mitigate the need to even deliberate on the potential trade-offs between using an embedded document approach or a referenced document approach. That approach is caching and leveraging <\/span><span style=\"font-weight: 400;\"><code>ActiveSupport::Cache<\/code><\/span><span style=\"font-weight: 400;\">. Did you know you can do so with Couchbase with minimal extra configuration?<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The Couchbase Ruby SDK <\/span><a href=\"https:\/\/github.com\/couchbase\/couchbase-ruby-client\/blob\/main\/lib\/active_support\/cache\/couchbase_store.rb\"><span style=\"font-weight: 400;\">includes support for an ActiveSupport cache store specifically for Couchbase data<\/span><\/a><span style=\"font-weight: 400;\">. This gives you all the benefits of ActiveSupport for your JSON document data. Let\u2019s take a quick look at how this would work.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Once you have the Couchbase SDK installed by adding <\/span><span style=\"font-weight: 400;\"><code>gem couchbase<\/code><\/span><span style=\"font-weight: 400;\"> to your <\/span><em><span style=\"font-weight: 400;\">Gemfile<\/span><\/em><span style=\"font-weight: 400;\"> and running <\/span><span style=\"font-weight: 400;\"><code>bundle install<\/code><\/span><span style=\"font-weight: 400;\"> from the command line, you are ready to integrate the caching support in your Rails application.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">First, define the Couchbase store in your <\/span><em><span style=\"font-weight: 400;\">config.rb<\/span><\/em><span style=\"font-weight: 400;\">:<\/span><\/p>\n<pre class=\"nums:false lang:ruby decode:true\">config.cache_store = :couchbase_store, {\r\n\u00a0\u00a0connection_string: # YOUR_COUCHBASE_CAPELLA_CONNECTION_STRING\",\r\n\u00a0\u00a0username: YOUR_COUCHBASE_ACCESS_CREDENTIALS_USERNAME,\r\n\u00a0\u00a0password: YOUR_COUCHBASE_ACCESS_CREDENTIALS_PASSWORD\",\r\n\u00a0\u00a0bucket: YOUR_COUCHBASE_BUCKET_NAME\r\n}<\/pre>\n<p><span style=\"font-weight: 400;\">Then, you can create a helper method in your application to fetch any data and store it in cache. For example, let\u2019s say you are creating a blogging platform. Once an article is published, it often stays the same for a long period of time, and therefore is safe to keep in cache. Similarly, if you choose to embed comments in the article JSON document on Couchbase, you may only need to update the document and a fetch a new copy in cache whenever a new comment is added, which will certainly be less frequent than fetching the document for every single request regardless.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Your code may look like the following example. We create a method called<\/span><code><span style=\"font-weight: 400;\">#fetch_article_with_caching<\/span><\/code><span style=\"font-weight: 400;\"> that fetches the article from Couchbase and parses the results to get the article contents and the CAS value. The CAS (Compare and Swap) value represents the current state of the document, ensuring concurrency control for every write operation. It helps check if the state of data in the local cache matches the most recent state in the database. Our method uses the CAS value to either update the application cache or return the article from the cache, reducing trade-offs between embedded data in Couchbase and traditional relational data models.<\/span><\/p>\n<pre class=\"nums:false lang:ruby decode:true\"># Fetch an article with caching, checking for updates to comments or article\r\ndef fetch_article_with_caching(article_id)\r\n\u00a0\u00a0cache_key = \"article_#{article_id}\"\r\n\r\n\u00a0\u00a0# Fetch the article metadata (including CAS value)\r\n\u00a0\u00a0# CAS value is a token for concurrency control, check for document updates\r\n\u00a0\u00a0result = Article.bucket.default_collection.get(article_id, Couchbase::Options::Get(with_expiry: true))\r\n\u00a0\u00a0article = result.content\r\n\u00a0\u00a0cas = result.meta.cas\r\n\r\n\u00a0\u00a0# Fetch the cached article along with its CAS value\r\n\u00a0\u00a0cached_article, cached_cas = Rails.cache.read(cache_key)\r\n\r\n\u00a0\u00a0# Update the cache if the article or its comments have changed\r\n\u00a0\u00a0if cached_article.nil? || cached_cas != cas\r\n\u00a0\u00a0\u00a0\u00a0Rails.cache.write(cache_key, [article, cas], expires_in: 12.hours)\r\n\u00a0\u00a0else\r\n\u00a0\u00a0\u00a0\u00a0article = cached_article\r\n\u00a0\u00a0end\r\n\r\n\u00a0\u00a0article\r\nend\r\n\r\n# Example usage\r\narticle = fetch_article_with_caching(\"your_article_id\")<\/pre>\n<h2>No ActiveRecord\u2026 or, is there?<\/h2>\n<p><span style=\"font-weight: 400;\">You might think that transitioning to Couchbase means saying goodbye to the familiar ActiveRecord library. However, thanks to the new <\/span><a href=\"https:\/\/couchbase-ruby-orm.com\/\"><span style=\"font-weight: 400;\">Couchbase Ruby ORM<\/span><\/a><span style=\"font-weight: 400;\">, you can still enjoy an ActiveRecord-like experience when working with Couchbase in your Rails applications.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The Couchbase Ruby ORM provides an ORM layer that mimics the functionality and syntax of ActiveRecord, making the transition smoother for Rails developers. This library bridges the gap between the relational model you&#8217;re accustomed to and the document model used by Couchbase. It offers a syntax that Rails developers are familiar with, reducing the learning curve. You can define models, set attributes, and interact with the database in a manner similar to ActiveRecord.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">For example, perhaps you need to define an <\/span><em><span style=\"font-weight: 400;\">Article<\/span><\/em><span style=\"font-weight: 400;\"> class and create a new instance of it. Using the new ORM, doing so with Couchbase looks exactly like doing so with ActiveRecord.<\/span><\/p>\n<pre class=\"nums:false lang:ruby decode:true\">class Article &lt; CouchbaseOrm::Base\r\n\u00a0\u00a0attribute :title, type: String\r\n\u00a0\u00a0attribute :content, type: String\r\n\u00a0\u00a0attribute :comments, type: Array\r\nend\r\n\r\narticle = Article.create(title: \"My Article\", content: \"This is the content of the article...\")<\/pre>\n<p><span style=\"font-weight: 400;\">You are even able to define validations in the <\/span><em><span style=\"font-weight: 400;\">Article<\/span><\/em><span style=\"font-weight: 400;\"> class just like you would with ActiveRecord.<\/span><\/p>\n<pre class=\"nums:false lang:ruby decode:true\">class Article &lt; CouchbaseOrm::Base\r\n\u00a0\u00a0attribute :title, type: String\r\n\u00a0\u00a0attribute :content, type: String\r\n\u00a0\u00a0attribute :comments, type: Array\r\nend\r\n\r\n## Ensure that every new article has a title\r\nvalidates :title, presence: true\r\n\r\narticle = Article.create(title: \"My Article\", content: \"This is the content of the article...\")<\/pre>\n<p><span style=\"font-weight: 400;\">What about creating associations between different models? Perhaps you want to make sure that an article can fetch its comments by invoking a <\/span><em><span style=\"font-weight: 400;\">#comments<\/span><\/em><span style=\"font-weight: 400;\"> method using the <\/span><em><span style=\"font-weight: 400;\">has_many<\/span><\/em><span style=\"font-weight: 400;\"> macro. This, too, is possible.<\/span><\/p>\n<pre class=\"nums:false lang:ruby decode:true\">class Article &lt; CouchbaseOrm::Base\r\n \u00a0# Define the association and make it a destruction\u00a0\r\n\u00a0\u00a0# dependency when an article is deleted\r\n\u00a0\u00a0has_many :comments, dependent: destroy\r\n\r\n\u00a0\u00a0attribute :title, type: String\r\n\u00a0\u00a0attribute :content, type: String\r\n\u00a0\u00a0attribute :comments, type: Array\r\nend\r\n\r\nvalidates :title, presence: true\r\n\r\narticle = Article.create(title: \"My Article\", content: \"This is the content of the article...\")<\/pre>\n<h2>Unique considerations<\/h2>\n<p><span style=\"font-weight: 400;\">As you introduce Couchbase as your database in your Rails application, there are some things to consider that by doing so early will make your development work smoother and more efficient. First, as the Ruby ORM is very new, there is not yet a testing library that you can integrate into RSpec to create your mocks, stubs and define matchers as you build your testing.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">This means that you will need to define your own mocks and other testing related items. For example, you can create a mock of an article and define an expectation around it.<\/span><\/p>\n<pre class=\"nums:false lang:ruby decode:true\">RSpec.describe Article, type: :model do\r\n\u00a0let(:article) do\r\n\u00a0\u00a0\u00a0\u00a0Article.new(id: 'article-id', title: 'Test Title', description: 'Test Description', body: 'Test Body', author_id: author.id)\r\n\u00a0\u00a0end\r\n\r\ncontext 'when saving an article' do\r\n\u00a0\u00a0\u00a0\u00a0describe '#save' do\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0it 'creates a new article record in the database' do\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0allow(Article).to receive(:new).and_return(article)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0allow(article).to receive(:save).and_return(true)\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0article.save\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0expect(article.id).to eq('article-id')\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0end\r\n\u00a0\u00a0\u00a0\u00a0end\r\n\u00a0\u00a0end\r\nend<\/pre>\n<p><span style=\"font-weight: 400;\">Another important feature of Couchbase data to remember is the role of <\/span><a href=\"https:\/\/docs.couchbase.com\/cloud\/n1ql\/n1ql-language-reference\/indexing-meta-info.html\"><span style=\"font-weight: 400;\">Metadata<\/span><\/a><span style=\"font-weight: 400;\"> in a Couchbase document. Metadata includes various pieces of information about the document, such as the document ID, the CAS value, expiration time, and more. This metadata can be helpful for managing and interacting with your data.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">One of the key components of metadata is the document ID. The document ID is a unique identifier for each document in Couchbase. It allows you to retrieve, update, and delete documents based on this ID. Unlike relational databases where you often use primary keys, Couchbase relies on these document IDs to uniquely identify each JSON document.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">To access the metadata of any of your JSON documents, you can create a custom query using the Ruby ORM. In the example below, the document ID is fetched by defining first the query and then a method to use it. The method returns both the document ID and the rest of the article data.<\/span><\/p>\n<pre class=\"nums:false lang:ruby decode:true\">class Article &lt; CouchbaseOrm::Base\r\n\u00a0\u00a0attribute :title, type: String\r\n\u00a0\u00a0attribute :content, type: String\r\n\u00a0\u00a0attribute :comments, type: Array\r\n\r\n\u00a0\u00a0# Custom query to fetch metadata ID along with article data\r\n\u00a0\u00a0n1ql :by_id_with_meta, emit_key: [:id], query_fn: proc { |bucket, values, options|\r\n\u00a0\u00a0\u00a0\u00a0cluster.query(\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"SELECT META(a).id AS meta_id, a.*\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0FROM `#{bucket.name}` AS a\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0WHERE META(a).id = $1\",\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Couchbase::Options::Query(positional_parameters: values)\r\n\u00a0\u00a0\u00a0\u00a0)\r\n\u00a0\u00a0}\r\nend\r\n\r\n# Fetch and display the article with its metadata ID\r\ndef fetch_article_with_meta_id(article_id)\r\n\u00a0\u00a0results = Article.by_id_with_meta(article_id)\r\n\u00a0\u00a0results.each do |row|\r\n\u00a0\u00a0\u00a0\u00a0meta_id = row[\"meta_id\"]\r\n\u00a0\u00a0\u00a0\u00a0article_data = row.reject { |key| key == \"meta_id\" }\r\n\u00a0\u00a0\u00a0\u00a0puts \"Meta ID: #{meta_id}\"\r\n\u00a0\u00a0\u00a0\u00a0puts \"Article Data: #{article_data}\"\r\n\u00a0\u00a0end\r\nend\r\n\r\n# Example usage\r\nfetch_article_with_meta_id(\"your_article_id\")<\/pre>\n<p><span style=\"font-weight: 400;\">If you are not familiar with Couchbase yet, you may look at that query and think it looks a lot like SQL, and you would be correct! One of the great things about Couchbase is it introduced a query language \u2013 <\/span><a href=\"https:\/\/www.couchbase.com\/products\/n1ql\/\"><span style=\"font-weight: 400;\">SQL++<\/span><\/a><span style=\"font-weight: 400;\"> \u2013\u00a0 for NoSQL documents that provides the same experience for interacting with them as one would with a SQL table. Working with your data in Couchbase with SQL++ provides the same functionality and ergonomics you are familiar with in any SQL database. There is no need to introduce any additional cognitive overhead to your work. That\u2019s the last thing any of us needs!\u00a0<\/span><\/p>\n<pre class=\"nums:false wrap:true lang:default decode:true \">SELECT META(a).id AS meta_id, a.* FROM `#{bucket.name}` AS a WHERE META(a).id = $1<\/pre>\n<h2>Wrapping Up<\/h2>\n<p><span style=\"font-weight: 400;\">The combination of an ORM to provide an ActiveRecord-like experience for your dynamic NoSQL data in Rails and a SQL-like query language to cover other use cases offers a fully versatile database and data management system for your application. If you are interested in exploring what a complete functioning implementation looks like, you can clone and dive into a real world example Rails application that covers all create, read, update and delete operations using the Ruby ORM on <\/span><a href=\"https:\/\/github.com\/hummusonrails\/realworld-couchbase-ruby-orm\/tree\/main\"><span style=\"font-weight: 400;\">GitHub<\/span><\/a><span style=\"font-weight: 400;\">.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Whenever your application requires data that does not easily conform to a rigid schema or a strictly defined structure and you are looking for how to accommodate that, Couchbase with the new Ruby ORM offers a compelling solution.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ruby on Rails is often the framework of choice for getting new projects off the ground. The speed of development and iteration is in many ways unparalleled. As such, perhaps you want to use Rails as the framework for your [&hellip;]<\/p>\n","protected":false},"author":85356,"featured_media":15989,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[1814,1815,2225,1816,9407,2201],"tags":[9984,1395],"ppma_author":[9985],"class_list":["post-15981","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-application-design","category-best-practices-and-tutorials","category-cloud","category-couchbase-server","category-ruby","category-tools-sdks","tag-orm","tag-rails"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.7.1 (Yoast SEO v25.7) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Couchbase on Rails: A Guide to Introducing Dynamic and Adaptive Data to Your Application - The Couchbase Blog<\/title>\n<meta name=\"description\" content=\"In this guide, you will discover the considerations and steps to utilizing Couchbase as your database fully integrated into your Rails application.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.couchbase.com\/blog\/couchbase-rails-guide-adaptive-data\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Couchbase on Rails: A Guide to Introducing Dynamic and Adaptive Data to Your Application\" \/>\n<meta property=\"og:description\" content=\"In this guide, you will discover the considerations and steps to utilizing Couchbase as your database fully integrated into your Rails application.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/blog\/couchbase-rails-guide-adaptive-data\/\" \/>\n<meta property=\"og:site_name\" content=\"The Couchbase Blog\" \/>\n<meta property=\"article:published_time\" content=\"2024-06-28T20:15:46+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-06-14T04:11:02+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2024\/06\/realworld_readme_banner-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1280\" \/>\n\t<meta property=\"og:image:height\" content=\"640\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Ben Greenberg, Senior Developer Evangelist\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ben Greenberg, Senior Developer Evangelist\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/couchbase-rails-guide-adaptive-data\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/couchbase-rails-guide-adaptive-data\/\"},\"author\":{\"name\":\"Ben Greenberg, Senior Developer Evangelist\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/48efa1524aec97312d92f65a270c255d\"},\"headline\":\"Couchbase on Rails: A Guide to Introducing Dynamic and Adaptive Data to Your Application\",\"datePublished\":\"2024-06-28T20:15:46+00:00\",\"dateModified\":\"2025-06-14T04:11:02+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/couchbase-rails-guide-adaptive-data\/\"},\"wordCount\":1613,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/couchbase-rails-guide-adaptive-data\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2024\/06\/realworld_readme_banner-1.png\",\"keywords\":[\"orm\",\"Rails\"],\"articleSection\":[\"Application Design\",\"Best Practices and Tutorials\",\"Couchbase Capella\",\"Couchbase Server\",\"Ruby\",\"Tools &amp; SDKs\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/couchbase-rails-guide-adaptive-data\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/couchbase-rails-guide-adaptive-data\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/couchbase-rails-guide-adaptive-data\/\",\"name\":\"Couchbase on Rails: A Guide to Introducing Dynamic and Adaptive Data to Your Application - The Couchbase Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/couchbase-rails-guide-adaptive-data\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/couchbase-rails-guide-adaptive-data\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2024\/06\/realworld_readme_banner-1.png\",\"datePublished\":\"2024-06-28T20:15:46+00:00\",\"dateModified\":\"2025-06-14T04:11:02+00:00\",\"description\":\"In this guide, you will discover the considerations and steps to utilizing Couchbase as your database fully integrated into your Rails application.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/couchbase-rails-guide-adaptive-data\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/couchbase-rails-guide-adaptive-data\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/couchbase-rails-guide-adaptive-data\/#primaryimage\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2024\/06\/realworld_readme_banner-1.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2024\/06\/realworld_readme_banner-1.png\",\"width\":1280,\"height\":640},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/couchbase-rails-guide-adaptive-data\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.couchbase.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Couchbase on Rails: A Guide to Introducing Dynamic and Adaptive Data to Your Application\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"name\":\"The Couchbase Blog\",\"description\":\"Couchbase, the NoSQL Database\",\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\",\"name\":\"The Couchbase Blog\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"width\":218,\"height\":34,\"caption\":\"The Couchbase Blog\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/48efa1524aec97312d92f65a270c255d\",\"name\":\"Ben Greenberg, Senior Developer Evangelist\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/c9bda12524045d12a5878a2ef3fbe0de\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2024\/06\/T024FJS4M-U075H3NTJUR-b4c321d902e2-512.jpeg\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2024\/06\/T024FJS4M-U075H3NTJUR-b4c321d902e2-512.jpeg\",\"caption\":\"Ben Greenberg, Senior Developer Evangelist\"},\"url\":\"https:\/\/www.couchbase.com\/blog\/author\/bengreenberg\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Couchbase on Rails: A Guide to Introducing Dynamic and Adaptive Data to Your Application - The Couchbase Blog","description":"In this guide, you will discover the considerations and steps to utilizing Couchbase as your database fully integrated into your Rails application.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.couchbase.com\/blog\/couchbase-rails-guide-adaptive-data\/","og_locale":"en_US","og_type":"article","og_title":"Couchbase on Rails: A Guide to Introducing Dynamic and Adaptive Data to Your Application","og_description":"In this guide, you will discover the considerations and steps to utilizing Couchbase as your database fully integrated into your Rails application.","og_url":"https:\/\/www.couchbase.com\/blog\/couchbase-rails-guide-adaptive-data\/","og_site_name":"The Couchbase Blog","article_published_time":"2024-06-28T20:15:46+00:00","article_modified_time":"2025-06-14T04:11:02+00:00","og_image":[{"width":1280,"height":640,"url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2024\/06\/realworld_readme_banner-1.png","type":"image\/png"}],"author":"Ben Greenberg, Senior Developer Evangelist","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Ben Greenberg, Senior Developer Evangelist","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.couchbase.com\/blog\/couchbase-rails-guide-adaptive-data\/#article","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/couchbase-rails-guide-adaptive-data\/"},"author":{"name":"Ben Greenberg, Senior Developer Evangelist","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/48efa1524aec97312d92f65a270c255d"},"headline":"Couchbase on Rails: A Guide to Introducing Dynamic and Adaptive Data to Your Application","datePublished":"2024-06-28T20:15:46+00:00","dateModified":"2025-06-14T04:11:02+00:00","mainEntityOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/couchbase-rails-guide-adaptive-data\/"},"wordCount":1613,"commentCount":0,"publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/couchbase-rails-guide-adaptive-data\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2024\/06\/realworld_readme_banner-1.png","keywords":["orm","Rails"],"articleSection":["Application Design","Best Practices and Tutorials","Couchbase Capella","Couchbase Server","Ruby","Tools &amp; SDKs"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.couchbase.com\/blog\/couchbase-rails-guide-adaptive-data\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/blog\/couchbase-rails-guide-adaptive-data\/","url":"https:\/\/www.couchbase.com\/blog\/couchbase-rails-guide-adaptive-data\/","name":"Couchbase on Rails: A Guide to Introducing Dynamic and Adaptive Data to Your Application - The Couchbase Blog","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/couchbase-rails-guide-adaptive-data\/#primaryimage"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/couchbase-rails-guide-adaptive-data\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2024\/06\/realworld_readme_banner-1.png","datePublished":"2024-06-28T20:15:46+00:00","dateModified":"2025-06-14T04:11:02+00:00","description":"In this guide, you will discover the considerations and steps to utilizing Couchbase as your database fully integrated into your Rails application.","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/blog\/couchbase-rails-guide-adaptive-data\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/blog\/couchbase-rails-guide-adaptive-data\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/couchbase-rails-guide-adaptive-data\/#primaryimage","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2024\/06\/realworld_readme_banner-1.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2024\/06\/realworld_readme_banner-1.png","width":1280,"height":640},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/blog\/couchbase-rails-guide-adaptive-data\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Couchbase on Rails: A Guide to Introducing Dynamic and Adaptive Data to Your Application"}]},{"@type":"WebSite","@id":"https:\/\/www.couchbase.com\/blog\/#website","url":"https:\/\/www.couchbase.com\/blog\/","name":"The Couchbase Blog","description":"Couchbase, the NoSQL Database","publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.couchbase.com\/blog\/#organization","name":"The Couchbase Blog","url":"https:\/\/www.couchbase.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","width":218,"height":34,"caption":"The Couchbase Blog"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/48efa1524aec97312d92f65a270c255d","name":"Ben Greenberg, Senior Developer Evangelist","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/c9bda12524045d12a5878a2ef3fbe0de","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2024\/06\/T024FJS4M-U075H3NTJUR-b4c321d902e2-512.jpeg","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2024\/06\/T024FJS4M-U075H3NTJUR-b4c321d902e2-512.jpeg","caption":"Ben Greenberg, Senior Developer Evangelist"},"url":"https:\/\/www.couchbase.com\/blog\/author\/bengreenberg\/"}]}},"authors":[{"term_id":9985,"user_id":85356,"is_guest":0,"slug":"bengreenberg","display_name":"Ben Greenberg, Senior Developer Evangelist","avatar_url":{"url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2024\/06\/T024FJS4M-U075H3NTJUR-b4c321d902e2-512.jpeg","url2x":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2024\/06\/T024FJS4M-U075H3NTJUR-b4c321d902e2-512.jpeg"},"author_category":"","last_name":"Greenberg, Senior Developer Evangelist","first_name":"Ben","job_title":"Senior Developer Evangelist","user_url":"","description":""}],"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/15981","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/users\/85356"}],"replies":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/comments?post=15981"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/15981\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media\/15989"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media?parent=15981"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/categories?post=15981"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/tags?post=15981"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=15981"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}