{"id":17289,"date":"2017-06-01T12:15:41","date_gmt":"2017-06-01T09:15:41","guid":{"rendered":"https:\/\/www.webcodegeeks.com\/?p=17289"},"modified":"2017-06-01T10:53:19","modified_gmt":"2017-06-01T07:53:19","slug":"using-react-inside-rails-apps","status":"publish","type":"post","link":"https:\/\/www.webcodegeeks.com\/ruby\/using-react-inside-rails-apps\/","title":{"rendered":"Using React Inside Your Rails Apps"},"content":{"rendered":"<p>I have never felt as productive as I do in Rails. Yet, with front-end seemingly moving further away from server-rendered views toward React, Angular, Vue, and Ember, I was unsure where Rails fit into this picture. Would it be relegated only to apps with \u201csimple\u201d front-ends, where holding things together with jQuery still managed to work, or perhaps to its new API mode, serving up data via RESTful JSON feeds to be consumed by client-side code and mobile apps?<\/p>\n<p>The answer to that question may be yes, because Rails still does an amazing job at that. But perhaps the answer lies more in the realm of \u201cmaybe\u2026it depends\u201d. Would it be better to bring the best of the front-end and have it live happily within the Rails ecosystem?<\/p>\n<p>In this article, <a href=\"https:\/\/github.com\/marianserna\">Marian Serna<\/a> and I will explore different ways of using React inside of your new or existing Rails apps.<\/p>\n<h2>Rails Embraces JavaScript<\/h2>\n<p>JavaScript has its flaws and that\u2019s why Rails embraced CoffeeScript early on instead of plain JS. With ES6 and Babel, CoffeeScript seemed less and less necessary, and in fact to me became something I disliked writing when most examples and articles online were using ES6 syntax. The <a href=\"http:\/\/js2.coffee\/\">js2coffee<\/a> website came in handy to convert between the two syntaxes.<\/p>\n<p>Then came the issue of how to include JS libraries in your Rails app. The typical way would be to look for a \u201cRails\u201d version of the JS library on <a href=\"https:\/\/rubygems.org\">rubygems.org<\/a>, or perhaps take advantage of <a href=\"https:\/\/rails-assets.org\">rails-assets.org<\/a>. It was a good solution for the time, but to fully embrace JS and provide a more seamless integration, we needed the ability to have a <code>package.json<\/code> file to list our <a href=\"https:\/\/www.npmjs.com\/\">JS dependencies<\/a>, install them via <a href=\"https:\/\/yarnpkg.com\">yarn<\/a>, and then package them together with a tool like <a href=\"https:\/\/webpack.github.io\/\">webpack<\/a>.<\/p>\n<p>With Rails 5.1, it feels like we finally have a great JS story rather than one that is just passable. It comes with support for yarn, es6, and webpack. <a href=\"http:\/\/pixelatedworks.com\/articles\/embracing-change-rails51-adopts-yarn-webpack-and-the-js-ecosystem\/\">Read here<\/a> for a great intro to exactly what this includes. Also, though it\u2019s a paid course, I recommend the <a href=\"https:\/\/es6.io\">ES6 course by Wes Bos<\/a> as a great introduction to the new features of JS.<\/p>\n<h2>Rails Embraces React<\/h2>\n<p><a href=\"https:\/\/github.com\/shakacode\/react_on_rails\">React on Rails<\/a> is a gem that allows you to organize and use React inside of a Rails project, easily rendering components (and passing them data) from within your Rails views. Additionally, it allows you to take advantage of NPM JavaScript libraries with yarn.<\/p>\n<p>Although Rails 5.1 gives you some of this ability, React on Rails presents a nice alternative for people who want the best of the front-end within Rails. It creates a structured and complete solution where any front-end developer, who may not have any prior Rails experience, can jump in and feel at home.<\/p>\n<h2>Installation<\/h2>\n<p>For further details on installing React on Rails, please refer to the <a href=\"https:\/\/github.com\/shakacode\/react_on_rails#installation-summary\">installation guide<\/a>.<\/p>\n<p>The basic steps are as follows:<\/p>\n<ul>\n<li>gem <code>react_on_rails<\/code>, <code>~&gt; 7.0<\/code>, <code>&gt;= 7.0.4<\/code> + bundle install<\/li>\n<li>Commit<\/li>\n<li>Run <code>rails generate react_on_rails:install --help<\/code><\/li>\n<li>We want to install it with Redux: <code>rails generate<br \/>\nreact_on_rails:install --redux --node<\/code><\/li>\n<\/ul>\n<p>This will prepare your Rails application to be able to render React components by creating a client folder where all of your React work will take place. Additionally, it adds a \u2018HelloWorld\u2019 example that includes a controller, route, view, and a component. Use <code>git diff<\/code> to see which files have been added and\/or modified.<\/p>\n<p>One caveat we\u2019ve noticed with Rails 5.1 is that since it comes with a <code>package.json<\/code> file of its own, there may be a conflict and you will have to manually merge them together.<\/p>\n<p>Inside of the client folder, you will find a fully separate React setup that comes with its own <code>package.json<\/code> file, containing all of the NPM modules necessary to run React with Webpack and ES6. Webpack comes preconfigured. All of our components will live inside of <code>client\/app\/bundles<\/code>.<\/p>\n<h2>Our First Component<\/h2>\n<p>You can use as much or as little of React as you want in your Rails app. It doesn\u2019t need to take over the entire front-end. Here is an example using React to create a hamburger nav menu; one small piece of a larger page.<\/p>\n<p>Inside of the <a href=\"https:\/\/github.com\/marianserna\/portfolio\/blob\/master\/app\/views\/layouts\/application.html.haml\">application layout file<\/a>, a React component is rendered using the <code>react_component<\/code> helper method provided by react_on_rails.<\/p>\n<pre class=\"brush:php\">!!! 5\r\n%html\r\n  %head\r\n    ... typical head tags\r\n\r\n  %body\r\n    = react_component(\"NavMenu\", props: {}, prerender: false)<\/pre>\n<p>This produces the following HTML, which is then picked up by <code>react_on_rails<\/code>, and a component is initialized on your behalf.<\/p>\n<pre class=\"brush:php\">&lt;script type=\"application\/json\" class=\"js-react-on-rails-component\"&gt;{\"component_name\":\"NavMenu\",\"props\":{},\"trace\":false,\"dom_id\":\"NavMenu-react-component-f8e24b6a-a711-49e5-930b-1472e97665ec\"}&lt;\/script&gt;\r\n&lt;div id=\"NavMenu-react-component-f8e24b6a-a711-49e5-930b-1472e97665ec\"&gt;&lt;\/div&gt;<\/pre>\n<p>The actual component renders a material design hamburger menu using the <code>react-mfb<\/code> package. This component lives in <a href=\"https:\/\/github.com\/marianserna\/portfolio\/blob\/master\/client\/app\/bundles\/App\/components\/NavMenu.jsx\">client\/app\/bundles\/App\/components\/NavMenu.jsx<\/a>.<\/p>\n<pre class=\"brush:java\">import React from 'react';\r\nimport {Menu, MainButton, ChildButton} from 'react-mfb';\r\n\r\nexport default class NavMenu extends React.Component {\r\n  render() {\r\n    return(\r\n      &lt;Menu effect=\"zoomin\" method=\"click\" position=\"tr\"&gt;\r\n        &lt;MainButton iconResting=\"ion-drag\" iconActive=\"ion-close-round\" \/&gt;\r\n\r\n        &lt;ChildButton icon=\"ion-ios-home\" label=\"Home\"\r\n          onClick = {(e) =&gt; {}} href=\"\/\" \/&gt;\r\n        &lt;ChildButton icon=\"ion-android-laptop\" label=\"Work\"\r\n          onClick = {(e) =&gt; {}} href=\"\/work\" \/&gt;\r\n        &lt;ChildButton icon=\"ion-android-person\" label=\"About\"\r\n          onClick = {(e) =&gt; {}} href=\"\/about\" \/&gt;\r\n        &lt;ChildButton icon=\"ion-email\" label=\"Contact\"\r\n          onClick = {(e) =&gt; {}} href=\"\/contact\" \/&gt;\r\n      &lt;\/Menu&gt;\r\n    )\r\n  }\r\n}<\/pre>\n<p>One important note is how to expose your React components to Rails. Inside of the <a href=\"https:\/\/github.com\/marianserna\/portfolio\/blob\/master\/client\/app\/bundles\/App\/startup\/registration.jsx\">client\/app\/bundles\/App\/startup\/registration.jsx<\/a> file, you can register it:<\/p>\n<pre class=\"brush:java\">import ReactOnRails from 'react-on-rails';\r\nimport NavMenu from '..\/components\/NavMenu';\r\n\r\nReactOnRails.register({\r\n  NavMenu\r\n});<\/pre>\n<p>Visiting any page on <a href=\"https:\/\/www.marianserna.com\/\">www.marianserna.com<\/a>, you\u2019ll see the hamburger menu on the top-right hand corner of the screen.<\/p>\n<h2>Passing Data from Rails to React<\/h2>\n<p>In React, components generally have two types of \u201cdata\u201d to worry about: Props and State. Props are read-only data passed from a parent component to a child. State is data internal to and managed by a specific component. If you need state, that is up to you, but how you pass props from your Rails view to your React component is done like so:<\/p>\n<pre class=\"brush:php\">= react_component(\"CaseStudy\", props: {case_study: @case_study_props, code_highlights: @code_highlights_props, more_case_studies: @more_case_studies_props}, prerender: false)<\/pre>\n<p>These props will then arrive to the component\u2019s constructor function as a JS object, which you can then access with <code>this.props.case_study<\/code>, for example.<\/p>\n<pre class=\"brush:php\">export default class CaseStudy extends React.Component {\r\n  constructor(props, _railsContext) {\r\n    super(props);\r\n\r\n    \/\/ ... rest of constructor\r\n  }\r\n}<\/pre>\n<p>To see the rest of the component, it is available <a href=\"https:\/\/github.com\/marianserna\/portfolio\/blob\/master\/client\/app\/bundles\/App\/components\/CaseStudy.jsx\">here<\/a> and you can <a href=\"https:\/\/www.marianserna.com\/work\/hologram\">see it in action here<\/a>.<\/p>\n<h2>Posting Data Back to Rails<\/h2>\n<p>When you need to send data back to Rails, you have quite a few different options. You could use <code>jQuery.post<\/code>, <code>fetch<\/code> (remember to include a polyfill for older browser support), or a library like <code>axios<\/code>. These are just standard AJAX requests like you\u2019re used to. In this case, we\u2019re treating our Rails app like an API, usually expecting JSON as the response.<\/p>\n<p>In a slightly more in-depth <code>react_on_rails<\/code> integration, this is how you might post data to create a <code>House<\/code> object that has many related <code>Image<\/code> records. This takes advantage of Rails\u2019 <code>accepts_nested_attributes_for<\/code> ability to create parent and child records at the same time. The code <a href=\"https:\/\/github.com\/leighhalliday\/home-demo\">is available on GitHub<\/a>. Refer to the repo and the controllers\/models\/serializers to see how the Rails side of this example was done.<\/p>\n<pre class=\"brush:php\">submitForm = (e) =&gt; {\r\n  e.preventDefault();\r\n\r\n  \/\/ Build form data and format it in way Rails API expects\r\n  const data = new FormData();\r\n  data.append('house[city]', this.city.value);\r\n  data.append('house[price]', this.price.value);\r\n  data.append('house[description]', this.description.value);\r\n  Array.from(this.images.files).forEach((file, index) =&gt; {\r\n    data.append(`house[images_attributes][${index}][photo]`, file, file.name);\r\n  });\r\n\r\n  \/\/ Include CSRF token for form_authenticity validation\r\n  const config = {\r\n    headers: {\r\n      'Content-Type': 'multipart\/form-data',\r\n      'Accept': 'application\/json',\r\n      'X-CSRF-Token': ReactOnRails.authenticityToken()\r\n    }\r\n  };\r\n\r\n  \/\/ Post data to \/houses endpoint and update state upon response\r\n  axios.post('\/houses', data, config).then((response) =&gt; {\r\n    this.setState({\r\n      status: 'success',\r\n      houseId: response.data.id\r\n    });\r\n  });\r\n}<\/pre>\n<p>One thing you might have noticed is the ability to include the CSRF token in our POST request to Rails. This is functionality provided by <code>react_on_rails<\/code> and must be imported at the top of your file: <code>import ReactOnRails from 'react-on-rails';<\/code>. The complete file <a href=\"https:\/\/github.com\/leighhalliday\/home-demo\/blob\/master\/client\/app\/bundles\/Home\/components\/NewHouse.jsx\">can be found here<\/a>.<\/p>\n<p>!Sign up for a free Codeship Account<\/p>\n<h2>Managing State in Redux<\/h2>\n<p>As your app grows in complexity, it may be a good idea to avoid managing state in each of your components (or a single Main\/Parent component) and instead manage it using Redux. The talented <a href=\"https:\/\/twitter.com\/wesbos\">Wes Bos<\/a> again has a <a href=\"https:\/\/learnredux.com\/\">course for learning this<\/a>, which happens to be free!<\/p>\n<p><code>react_on_rails<\/code> comes with built-in support for Redux and all of the packages are included if you install it with the <code>--redux<\/code> option.<a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/06\/redux-cycle.jpg\"><img decoding=\"async\" class=\"aligncenter wp-image-17291\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/06\/redux-cycle.jpg\" alt=\"\" width=\"860\" height=\"484\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/06\/redux-cycle.jpg 1920w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/06\/redux-cycle-300x169.jpg 300w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/06\/redux-cycle-768x432.jpg 768w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/06\/redux-cycle-1024x576.jpg 1024w\" sizes=\"(max-width: 860px) 100vw, 860px\" \/><\/a><\/p>\n<p>Redux is very verbose and in my opinion sort of complicated to get set up. Thankfully the HelloWorld example of <code>react_on_rails<\/code> contains a complete setup. What you\u2019ll see are folders for the following items:<\/p>\n<ul>\n<li><strong>store:<\/strong> This is where you will define your Redux data store (or global state). You can include any middleware you may want, like <code>thunk<\/code>, which we\u2019ll touch on very briefly below.<\/li>\n<li><strong>actions:<\/strong> Actions in redux are functions which are in charge of preparing data and talking with external resources before finally dispatching an event with the goal of updating the store\u2019s state. Your business logic lives here. These work hand in hand with reducers which we\u2019ll talk about below.<\/li>\n<li><strong>constants:<\/strong> These are constants so that the actions and reducers can refer to the same events. It is how the action tells the reducer which data is going to be changed.<\/li>\n<li><strong>reducers:<\/strong> Reducers have the task of taking the existing copy of the store\u2019s state and producing a new version of it based on the data dispatched\/returned from an action.<\/li>\n<li><strong>containers:<\/strong> This is the glue between a Component and the Redux store + actions. They are small wrappers which pass the Redux store as props to the component. Any time a store\u2019s data is updated, the component will receive those updates via props to force a rerender.<\/li>\n<\/ul>\n<p>Without going into the full complexity of Redux, we\u2019ll try to show a simple example below that fetches the information for a single <code>House<\/code> object in our demo app.<\/p>\n<p>When the <a href=\"https:\/\/github.com\/leighhalliday\/home-demo\/blob\/master\/client\/app\/bundles\/Home\/components\/HouseInfo.jsx\">HouseInfo component<\/a> mounts, it will make a call to the action, telling it which house it needs data for.<\/p>\n<pre class=\"brush:php\">componentWillMount() {\r\n  this.props.loadHouse(this.props.match.params.id);\r\n}<\/pre>\n<p>The <code>loadHouse<\/code> action lives inside of a file which <a href=\"https:\/\/github.com\/leighhalliday\/home-demo\/blob\/master\/client\/app\/bundles\/Home\/actions\/homeActionCreators.jsx\">contains all related actions<\/a>. Because this AJAX request happens asynchronously, our <code>loadHouse<\/code> will return a function that will get passed a <code>dispatch<\/code> function. <code>dispatch<\/code> can be called any time we have more information we want to update in the store (via a reducer).<\/p>\n<p>For more information on dealing with asynchronous code inside of Redux, check out the <a href=\"https:\/\/github.com\/gaearon\/redux-thunk\">redux-thunk<\/a> library.<\/p>\n<pre class=\"brush:php\">export const loadHouse = (id) =&gt; {\r\n  return (dispatch) =&gt; {\r\n    \/\/ Make sure there isn't an existing house in the store\r\n    \/\/ Also allows us to show a \"Loading...\" screen\r\n    dispatch({type: LOAD_HOUSE, house: null});\r\n\r\n    \/\/ Make AJAX request to Rails endpoint\r\n    axios.get(`\/houses\/${id}`, {\r\n      headers: {'Content-Type': 'application\/json', 'Accept': 'application\/json'}\r\n    }).then((response) =&gt; {\r\n      \/\/ Upon response, dispatch another event with the house data\r\n      dispatch({\r\n        type: LOAD_HOUSE,\r\n        house: response.data\r\n      });\r\n    });\r\n  }\r\n}<\/pre>\n<p>Now it\u2019s time for <a href=\"https:\/\/github.com\/leighhalliday\/home-demo\/blob\/master\/client\/app\/bundles\/Home\/reducers\/homeReducer.jsx\">the reducer<\/a> to create a new version of the state based on the events dispatched above.<\/p>\n<pre class=\"brush:php\">\/\/ Load our constants, the link between actions &amp; reducers\r\nimport {\r\n  LOAD_HOUSE,\r\n  LOAD_FEATURED_HOUSES,\r\n  SEARCH_HOUSES\r\n} from '..\/constants\/homeConstants';\r\n\r\nconst homeReducer = (state = {}, action) =&gt; {\r\n  \/\/ Look for the action.type to determine what state needs to change\r\n  switch (action.type) {\r\n    case LOAD_HOUSE:\r\n      \/\/ Create a copy and then modify copy of state using ES6 spread operator\r\n      return {...state, house: action.house};\r\n    case LOAD_FEATURED_HOUSES:\r\n      return {...state, houses: action.houses};\r\n    case SEARCH_HOUSES:\r\n      return {...state, houses: action.houses};\r\n    default:\r\n      \/\/ We didn't understand any of the action types, return existing state unchanged\r\n      return state;\r\n  }\r\n};\r\n\r\nexport default homeReducer;<\/pre>\n<h2>Client Side Routing in React<\/h2>\n<p>If we want routing to be handled client-side using <a href=\"https:\/\/reacttraining.com\/react-router\/\">React Router<\/a>, this isn\u2019t a problem with <code>react_on_rails<\/code>. The trick to make it work is that you\u2019ll essentially have to handle routing twice\u2026once inside of Rails (which will render the component) and then again inside of React.<\/p>\n<p>The Rails routes are pretty standard:<\/p>\n<pre class=\"brush:php\">Rails.application.routes.draw do\r\n  root to: \"houses#index\"\r\n\r\n  resources :houses, only: [:new, :show, :create] do\r\n    collection do\r\n      get :featured\r\n      get :search\r\n    end\r\n  end\r\nend<\/pre>\n<p>What you don\u2019t see here is that <code>houses#index<\/code>, <code>houses#show<\/code>, and <code>houses#new<\/code> all render the same component:<\/p>\n<pre class=\"brush:php\">= react_component(\"HomeApp\", props: {}, prerender: false)<\/pre>\n<p>This <code>HomeApp<\/code> component then takes over and figures out the routing on the client side.<\/p>\n<pre class=\"brush:xml\">const HomeApp = (props, _railsContext) =&gt; {\r\n  const store = configureStore(props);\r\n\r\n  return (\r\n    &lt;Provider store={store}&gt;\r\n      &lt;BrowserRouter&gt;\r\n        &lt;Switch&gt;\r\n          &lt;Route path=\"\/\" exact component={HomeContainer} \/&gt;\r\n          &lt;Route path=\"\/houses\/new\" component={NewHouseContainer} \/&gt;\r\n          &lt;Route path=\"\/houses\/:id\" component={HouseInfoContainer} \/&gt;\r\n        &lt;\/Switch&gt;\r\n      &lt;\/BrowserRouter&gt;\r\n    &lt;\/Provider&gt;\r\n  );\r\n};<\/pre>\n<p>One thing that caused some confusion was not having <code>Switch<\/code> wrapping the routes\u2026it was causing ambiguous routing, thinking that the \u201cnew\u201d part of <code>\"\/houses\/new\"<\/code> was actually an ID of a house. <code>Switch<\/code> deals with this by sticking with the route that matches correctly first, so the order you list them in is important.<\/p>\n<h2>A Word on Authentication<\/h2>\n<p>Because authentication in this demo app was done via Devise, we stuck with using the typical cookie-based user session.<\/p>\n<p>As you move more and more toward your entire app living in React, or even supporting ReactNative or other native apps, you might be better off not assuming that cookies will exist and instead looking into <a href=\"https:\/\/jwt.io\/\">JSON Web Tokens<\/a>. This is beyond the scope of the article though, so will have to be explored at a later date.<\/p>\n<h2>Conclusion<\/h2>\n<p>We hope we were able to show that including React inside of your Rails app is not only possible, it is a fairly elegant solution to including more front-end interactivity and avoiding the spaghetti code that jQuery can often end up turning into.<\/p>\n<p>It\u2019s up to you how much or how little to include. It can be as small as a nav component on a specific page, it can be an entire page of your app, or you can use Redux + React Router to take over larger and larger areas of your application.<\/p>\n<p>Don\u2019t feel the need to abandon server-rendered code. It can still be a joy to write and is often the most simple solution. At the same time, it\u2019s great being able to take advantage of all the cutting edge client-side code available these days.<\/p>\n<div class=\"attribution\">\n<table>\n<tbody>\n<tr>\n<td><span class=\"reference\">Reference: <\/span><\/td>\n<td><a href=\"https:\/\/blog.codeship.com\/using-react-inside-your-rails-apps\/\">Using React Inside Your Rails Apps<\/a> from our <a href=\"http:\/\/www.webcodegeeks.com\/join-us\/wcg\/\">WCG partner<\/a> Leigh Halliday at the <a href=\"http:\/\/blog.codeship.com\/\">Codeship Blog<\/a> blog.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>I have never felt as productive as I do in Rails. Yet, with front-end seemingly moving further away from server-rendered views toward React, Angular, Vue, and Ember, I was unsure where Rails fit into this picture. Would it be relegated only to apps with \u201csimple\u201d front-ends, where holding things together with jQuery still managed to &hellip;<\/p>\n","protected":false},"author":113,"featured_media":4127,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[95,468],"class_list":["post-17289","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ruby","tag-rails","tag-react"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Using React Inside Your Rails Apps - Web Code Geeks - 2026<\/title>\n<meta name=\"description\" content=\"I have never felt as productive as I do in Rails. Yet, with front-end seemingly moving further away from server-rendered views toward React, Angular, Vue,\" \/>\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.webcodegeeks.com\/ruby\/using-react-inside-rails-apps\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Using React Inside Your Rails Apps - Web Code Geeks - 2026\" \/>\n<meta property=\"og:description\" content=\"I have never felt as productive as I do in Rails. Yet, with front-end seemingly moving further away from server-rendered views toward React, Angular, Vue,\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webcodegeeks.com\/ruby\/using-react-inside-rails-apps\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webcodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2017-06-01T09:15:41+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/rubyonrails-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Leigh Halliday\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@leighchalliday\" \/>\n<meta name=\"twitter:site\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Leigh Halliday\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"13 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.webcodegeeks.com\/ruby\/using-react-inside-rails-apps\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/ruby\/using-react-inside-rails-apps\/\"},\"author\":{\"name\":\"Leigh Halliday\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/e496b17f78cdca27723b8e225dc6ab6b\"},\"headline\":\"Using React Inside Your Rails Apps\",\"datePublished\":\"2017-06-01T09:15:41+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/ruby\/using-react-inside-rails-apps\/\"},\"wordCount\":1890,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/ruby\/using-react-inside-rails-apps\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/rubyonrails-logo.jpg\",\"keywords\":[\"Rails\",\"React\"],\"articleSection\":[\"Ruby\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.webcodegeeks.com\/ruby\/using-react-inside-rails-apps\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.webcodegeeks.com\/ruby\/using-react-inside-rails-apps\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/ruby\/using-react-inside-rails-apps\/\",\"name\":\"Using React Inside Your Rails Apps - Web Code Geeks - 2026\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/ruby\/using-react-inside-rails-apps\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/ruby\/using-react-inside-rails-apps\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/rubyonrails-logo.jpg\",\"datePublished\":\"2017-06-01T09:15:41+00:00\",\"description\":\"I have never felt as productive as I do in Rails. Yet, with front-end seemingly moving further away from server-rendered views toward React, Angular, Vue,\",\"breadcrumb\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/ruby\/using-react-inside-rails-apps\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.webcodegeeks.com\/ruby\/using-react-inside-rails-apps\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/ruby\/using-react-inside-rails-apps\/#primaryimage\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/rubyonrails-logo.jpg\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/rubyonrails-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.webcodegeeks.com\/ruby\/using-react-inside-rails-apps\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.webcodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Ruby\",\"item\":\"https:\/\/www.webcodegeeks.com\/category\/ruby\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Using React Inside Your Rails Apps\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"name\":\"Web Code Geeks\",\"description\":\"Web Developers Resource Center\",\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.webcodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webcodegeeks\",\"https:\/\/x.com\/webcodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/e496b17f78cdca27723b8e225dc6ab6b\",\"name\":\"Leigh Halliday\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/bd40251a1acc424c292c35a3485264a801efa20efa7063c3e320a0a354ddafac?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/bd40251a1acc424c292c35a3485264a801efa20efa7063c3e320a0a354ddafac?s=96&d=mm&r=g\",\"caption\":\"Leigh Halliday\"},\"description\":\"Leigh is a developer at theScore. He writes about Ruby, Rails, and software development on his personal site.\",\"sameAs\":[\"http:\/\/www.leighhalliday.com\/\",\"https:\/\/x.com\/leighchalliday\"],\"url\":\"https:\/\/www.webcodegeeks.com\/author\/leigh-halliday\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Using React Inside Your Rails Apps - Web Code Geeks - 2026","description":"I have never felt as productive as I do in Rails. Yet, with front-end seemingly moving further away from server-rendered views toward React, Angular, Vue,","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.webcodegeeks.com\/ruby\/using-react-inside-rails-apps\/","og_locale":"en_US","og_type":"article","og_title":"Using React Inside Your Rails Apps - Web Code Geeks - 2026","og_description":"I have never felt as productive as I do in Rails. Yet, with front-end seemingly moving further away from server-rendered views toward React, Angular, Vue,","og_url":"https:\/\/www.webcodegeeks.com\/ruby\/using-react-inside-rails-apps\/","og_site_name":"Web Code Geeks","article_publisher":"https:\/\/www.facebook.com\/webcodegeeks","article_published_time":"2017-06-01T09:15:41+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/rubyonrails-logo.jpg","type":"image\/jpeg"}],"author":"Leigh Halliday","twitter_card":"summary_large_image","twitter_creator":"@leighchalliday","twitter_site":"@webcodegeeks","twitter_misc":{"Written by":"Leigh Halliday","Est. reading time":"13 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.webcodegeeks.com\/ruby\/using-react-inside-rails-apps\/#article","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/ruby\/using-react-inside-rails-apps\/"},"author":{"name":"Leigh Halliday","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/e496b17f78cdca27723b8e225dc6ab6b"},"headline":"Using React Inside Your Rails Apps","datePublished":"2017-06-01T09:15:41+00:00","mainEntityOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/ruby\/using-react-inside-rails-apps\/"},"wordCount":1890,"commentCount":0,"publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/ruby\/using-react-inside-rails-apps\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/rubyonrails-logo.jpg","keywords":["Rails","React"],"articleSection":["Ruby"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.webcodegeeks.com\/ruby\/using-react-inside-rails-apps\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.webcodegeeks.com\/ruby\/using-react-inside-rails-apps\/","url":"https:\/\/www.webcodegeeks.com\/ruby\/using-react-inside-rails-apps\/","name":"Using React Inside Your Rails Apps - Web Code Geeks - 2026","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/ruby\/using-react-inside-rails-apps\/#primaryimage"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/ruby\/using-react-inside-rails-apps\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/rubyonrails-logo.jpg","datePublished":"2017-06-01T09:15:41+00:00","description":"I have never felt as productive as I do in Rails. Yet, with front-end seemingly moving further away from server-rendered views toward React, Angular, Vue,","breadcrumb":{"@id":"https:\/\/www.webcodegeeks.com\/ruby\/using-react-inside-rails-apps\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webcodegeeks.com\/ruby\/using-react-inside-rails-apps\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/ruby\/using-react-inside-rails-apps\/#primaryimage","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/rubyonrails-logo.jpg","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/rubyonrails-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.webcodegeeks.com\/ruby\/using-react-inside-rails-apps\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.webcodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Ruby","item":"https:\/\/www.webcodegeeks.com\/category\/ruby\/"},{"@type":"ListItem","position":3,"name":"Using React Inside Your Rails Apps"}]},{"@type":"WebSite","@id":"https:\/\/www.webcodegeeks.com\/#website","url":"https:\/\/www.webcodegeeks.com\/","name":"Web Code Geeks","description":"Web Developers Resource Center","publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.webcodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.webcodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.webcodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webcodegeeks","https:\/\/x.com\/webcodegeeks"]},{"@type":"Person","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/e496b17f78cdca27723b8e225dc6ab6b","name":"Leigh Halliday","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/bd40251a1acc424c292c35a3485264a801efa20efa7063c3e320a0a354ddafac?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/bd40251a1acc424c292c35a3485264a801efa20efa7063c3e320a0a354ddafac?s=96&d=mm&r=g","caption":"Leigh Halliday"},"description":"Leigh is a developer at theScore. He writes about Ruby, Rails, and software development on his personal site.","sameAs":["http:\/\/www.leighhalliday.com\/","https:\/\/x.com\/leighchalliday"],"url":"https:\/\/www.webcodegeeks.com\/author\/leigh-halliday\/"}]}},"_links":{"self":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/17289","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/users\/113"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/comments?post=17289"}],"version-history":[{"count":0,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/17289\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media\/4127"}],"wp:attachment":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media?parent=17289"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/categories?post=17289"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/tags?post=17289"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}