Posts

[ToDoList] Introduction to Routing

Image
Basic Routes     As moving and seminal as the Rails welcome page is, we probably want something a bit more personal as our homepage (site root). This can be quickly achieved by editing just two files that already exist in our app, starting with /config/routes.rb : config/routes.rb Rails.application.routes.draw do get "up" => "rails/health#show", as: :rails_health_check root 'pages#hello' ## in controller#method format (snake_case) end This will send all requests to the root (homepage) of the site to the #hello method in the PagesController . We can see if this worked by consulting the Rails routes table and seeing this entry in the resulting output: $ bundle exec rails routes Prefix Verb URI Pattern Controller#Action root GET / pages#hello (If the output of the c...

[ToDoList] Version Control 2: Electric Boogaloo

Image
Pushing to GitHub     With the skeleton of our app built and tested, let’s take the opportunity to make this the initial commit to our code repository. Hopefully you followed the previous instructions to install git, create your new GitHub repository and add your SSH key to it (do this now if not) - navigating to this blank repo will display instructions on how to initialise the app directory and push it to GitHub. For posterity, this is also below, with a few extra bits: $ git config --global user.name "{{YOUR NAME}}" ## set name $ git config --global user.email "{{YOUR EMAIL ADDRESS}}" ## set email $ git init ## initialise the repo $ git add -A ## stage all files $ git commit -m "{{COMMIT MESSAGE}}" ## commit files $ git branch -...

[ToDoList] Building the App

Image
The new Generator The Rails Development Server     So we have now learned some theory about Rails and set up our development environment with the required packages and version control prerequisites. I think that’s enough preamble, let’s get developing! The next few sections will involve creating a funky little web app that contains a To-Do list that we can add, remove and edit entries from. We saw a very small snippet of the extensive file structure that Rails uses in the first section. If you thought you’d be constructing the longest mkdir -p command in the observable universe to get all of this set up, you will be pleased to know (as I was) that our first utilisation of Rails magic will be to get Rails to generate all of this for us! Feel free to set up a projects directory on your dev machine, or you can just use your home dir if you’d prefer. Whatever you choose, change into this dir n...

Version Control (feat. SSH)

Image
GitHub Repository SSH Access     The last thing to discuss before we actually get to do something in Rails is version control . This might seem largely unnecessary within the remit of learning how to code with Rails, but using it while learning the rest of this stuff will pay off when you start writing your own apps without the help of this wonderful guide. When we come to deploy our app later on, you will also be glad you did this from the start! While other version control systems are available, this guide will focus on using git and its companion repository store, GitHub . Git does all the tricky bits of version control for you, so all you have to do is make sure you are pointing at the correct repo (sitory) and the right branch, and that you actually push your work to the repo! Git supports a number of repository stores, my particular favorite being GitHub which gives you unlimited free public reposi...

Rails Dev Environment Setup

Development Environment Packages & Dependencies     Before we can build our app, we need a suitable environment to work in - this will generally take the form of either some kind of virtual machine or using Docker. There are a number of ways we can get this set up depending on your local workstation’s resources and how you prefer to work: One of the easier / less resource intensive options will be to use an online IDE, meaning you won’t have to host anything on your local machine. I quite like https://codeanywhere.com/ , which you can use your Google account to access for free (because you definitely have a Google account, don't you?). Once signed up and on your Dashboard click New Container , give it a name and search for the Ruby stack, select it and hit OK . My overall recommended option for...

Rails Application Overview

Rails App Structure Cases in Rails     In essence, a Rails app is a group of files that follow particular conventions and architectural styles (i.e. MVC , CRUD ) in order to manage and serve applications built with Ruby. If you have seen the file structure of a Rails app before it may appear a little daunting, however we can usually get away with focusing only on the bits we will usually interact with: / The root of the application - everything in the app goes in here. Gemfile Lists all gems (Ruby libraries) used in the app. (The Gemfile.lock locks down versions of these gems). app/ Contains most of our written code, housing the components of the MVC architecture. ...

I upgraded to Ubuntu 22.04

As the needlessly ambiguous title declares, last night I upgraded my primary work laptop from Ubuntu 20.04 to 22.04 using Ubuntu's upgrade feature ( do-release-upgrade ). Note that I didn't do this blindly - I did install it quickly on a Virtual Machine to ensure that nothing was obviously wrong, but verification of this was quick and the upgrade process swiftly followed. Completely unexpectedly, this went (mostly) incredibly well! I replaced all of the flagged applications with the new versions during this process and, after a post-installation reboot, I am extremely impressed at how snazzy the new system looks! We've got an updated boot logo and a removal of purple from the default loading / login screen; we've got hover indications for almost every clickable option; we've got more vanilla theming customisation than ever. And we've still got GNOME as our default DE. These victories are true and real and cause for celebration. Howeve...

[ToDoList] Docker Compose

Image
We learned in the previous section how Docker is a fantastic tool with which to build and deploy applications, however has some inconveniences with developing these apps such as having to rebuild the image every time there is a code change as well as any development database entries being wiped. This section will offer some relief against these two issues by using Docker Compose to build our application and make live code changes, as well as using a separate container to host our development database in PostgreSQL - this will encompass three main tasks: Back up and edit the Dockerfile we made in the previous section so our image can be built. Create our docker-compose.yml in the app's root directory to create our web & postgresql database containers. Back up and edit some our app's configuration (namely the database.yml & Gemfile ) to use the new postgresql container . After all this, we can set about ...

[ToDoList] Dockerising the App

Image
So we've covered all the basic Ruby and Rails magic that has allowed us to build a basic web application, as well as made it look like a passably professional piece of work. This certainly deserves another whoop of celebration if you're not already whooped out. However at this point, you might already have run into problems with the joys Ruby / Rails / Bundler / Node versions, particularly if you have been working on different systems. It is also entirely possible that you're a bit sick of the VM or online IDE you are using to build the app, and you are hoping for a better solution. The solution to both of these is the mighty Docker ( other container frameworks are available ). You may have already heard of Docker, being a tool that essentially revolutionised app development and deployment by using a funky little addition to the Linux kernel: namespaces . Think of these almost as Virtual Machines (though much, much cooler an...

[ToDoList] Materialize V: Other Pages

Image
We have now made all of our Ruby action views look incredibly lovely and have the makings of a moderately sellable web application on our hands! All we have left to worry about are those pesky other views: home , about and help . Now, because we are almost a quarter of the way through the 2020s, gone are the days where we are expected to provide a home page for an application such as this. Even about and help pages are becoming significantly less common, as the average consumer seems to care little about who made the application they're using (that is, until something goes wrong and they'll want all of your personal information to contact you to fix it or punish you for not). With that in mind, you would be perfectly within your rights to simply do away with these views entirely and alter your Rails routes to point the root route at the todos#index view. However, because I am a child of the 1990s and like these touch...

Popular posts from this blog

[ToDoList] Front-end Basics

New Rails Apps with Docker Compose

[ToDoList] Data FUNdamentals