<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Fikerte on Medium]]></title>
        <description><![CDATA[Stories by Fikerte on Medium]]></description>
        <link>https://medium.com/@tofikertesfaye?source=rss-ded005a93774------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*kkQDu7kHzXTyQ1OX</url>
            <title>Stories by Fikerte on Medium</title>
            <link>https://medium.com/@tofikertesfaye?source=rss-ded005a93774------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 17:03:15 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tofikertesfaye/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to setup a project with React and RoR on windows]]></title>
            <link>https://medium.com/@tofikertesfaye/how-to-setup-a-project-with-react-and-ror-on-windows-4da179553a86?source=rss-ded005a93774------2</link>
            <guid isPermaLink="false">https://medium.com/p/4da179553a86</guid>
            <dc:creator><![CDATA[Fikerte]]></dc:creator>
            <pubDate>Thu, 23 Mar 2023 18:32:59 GMT</pubDate>
            <atom:updated>2023-03-23T18:32:59.224Z</atom:updated>
            <content:encoded><![CDATA[<p>The release of Rails 7 has changed how it handles javascript. Rails 7 now offers different ways to use React. For this setup its going to be webpack. Note: Before we dive into the setup make sure you have Postgresql, Ruby and Node.js installed on your machine.</p><p><strong>Setup Rails with Webpack</strong></p><p>Go to your desired folder and create your app using the following command</p><pre>rails new -j webpack name_of_your_app --database=postgresql</pre><ol><li>Make sure that the jsbundling-rails gem is in your gemfile</li><li>Run bundle install</li><li>Run rails javascript:install:webpack</li><li>Add the following development dependencies</li></ol><pre>yarn add react react-dom<br>yarn add @babel/core @babel/preset-env @babel/preset-react babel-loader --dev</pre><p>5. Add a babel.config.js in the root folder that contains</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/59d2f304411b1c8226e659cb62f000b3/href">https://medium.com/media/59d2f304411b1c8226e659cb62f000b3/href</a></iframe><p>6. Include the babel loader into webpack.config.js file</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/48b7b4fa93f31ff6f39c94e5eab32a44/href">https://medium.com/media/48b7b4fa93f31ff6f39c94e5eab32a44/href</a></iframe><p><strong>Connection with Database</strong></p><ol><li>Make sure to setup username and password to your database in config/database.yml file</li><li>Run rails db:create</li></ol><p><strong>Generate a model</strong></p><pre>rails g model Message title:string</pre><ol><li>Run rails db:migrate</li><li>Add some seed data in db/seeds.rb</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3973660bb94d82897e640f71b5133993/href">https://medium.com/media/3973660bb94d82897e640f71b5133993/href</a></iframe><p>3. Run rails db:seed</p><p><strong>Generate a controller and view that will be the root of the app</strong></p><pre>rails g controller Root index</pre><ol><li>Update the contents of app/views/root/index.html.erb as follows:</li></ol><pre>&lt;div id=&#39;root&#39;&gt;</pre><p>2. Add root path in config/routes.rb to the view</p><pre>Rails.application.routes.draw do<br>  root &#39;root#index&#39;<br>end</pre><p><strong>Create an API endpoint that selects random message from your DB table</strong></p><pre>rails g controller api/v1/messages</pre><p>This command creates a controller with an action and Rails route</p><ol><li>Update the contents of app/controllers/api/v1/messages_controller.rb with</li></ol><pre>class Api::V1::MessagesController &lt; ApplicationController<br>  def index<br>    @messages= Message.all<br>    render json: @messages.sample<br>  end<br>end</pre><p>2. Add the route to your API end point as follows in config/routes.rb and the final code looks like this</p><pre>Rails.application.routes.draw do<br>  root &#39;root#index&#39;<br>  namespace :api do<br>    namespace :v1 do<br>      get &quot;messages&quot;, to: &#39;messages#index&#39;<br>    end<br>  end<br>end</pre><p><strong>Add your react app</strong></p><p>Finally we are going to setup our react app with components, action, reducer and store.</p><p>First install the required dependencies</p><p>npm i react-router-dom @reduxjs/toolkit react-redux axios</p><p><strong>Components</strong></p><ol><li>Create a folder Components in app/javascript</li><li>In app/javascript/components, add the Message component that will display a message as follows</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7f2f48b9003e4b087172bd2baa485adb/href">https://medium.com/media/7f2f48b9003e4b087172bd2baa485adb/href</a></iframe><p>3. Also in app/javascript/Components create the App.js component with react-router and render it in your static view. Also setup Message.js component as a route in your App component as follows</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4c2e4e9200f8a0806a5b54ec4f4aaf3a/href">https://medium.com/media/4c2e4e9200f8a0806a5b54ec4f4aaf3a/href</a></iframe><p><strong>Setup reducer, action and store</strong></p><ol><li>Create a folder reduxin app/javascript</li><li>Go to app/javascript/redux and create message.js file. Then put the following code inside</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e6d98acd9fa28cfb7f674bfc1bd45d5b/href">https://medium.com/media/e6d98acd9fa28cfb7f674bfc1bd45d5b/href</a></iframe><p>3. Go to app/javascript/redux and create store.js file. Then put the following code inside</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cf206a399b7c181899ee3a9ff7f271ba/href">https://medium.com/media/cf206a399b7c181899ee3a9ff7f271ba/href</a></iframe><p>Finally you can start your application by first building your JavaScript with</p><p>npm run build</p><p>Then start rails server with</p><p>rails s</p><p>In your browser, go to http://localhost:3000/</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4da179553a86" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>