Installing software tends to either go swimmingly or you end up drowning in a Pool of Despair. In the Pool of Despair case, extra instructions don’t seem to help very much so I’ll keep mine to a minimum.
Open a terminal and go to that favourite part of your hard drive where you keep all your future dreams and create a rails project.
rails new blogging --database=postgresql --webpack=react --skip-turbolinks --skip-spring
I don’t like Turbolinks.
On four Mac Books in a row, Spring always pegs my CPU at 100% and I don’t know why.
–webpack=react will install Webpack and the node packages for React.
I’m going to push everything to Github so I can link to the code online. I just created a repository at https://github.com/klawrence/blogging
cd blogging git init git add . git commit -m 'Start blogging!' git remote add origin https://firstname.lastname@example.org/klawrence/blogging.git git push -u origin master
If the install gods are on our side we can create the database, start the server and see the happy, happy Welcome to Rails banner.
rails db:create rails server open http://localhost:3000/
When we created our Rails project, Webpacker created a HelloReact app. We can use that to test that React installed correctly. We’ll create a posts controller to initialize HelloReact and we’ll set it as the home page in routes.rb.
rails generate controller Posts index
#routes.rb Rails.application.routes.draw do root to: 'posts#index' resources :posts end
Now, when I go to http://localhost:3000/, I see the message “Hello, React”. I hope you do too.
Everything is set up now and we’re ready to start coding. In the next episode, we’ll show our first blog post.