Creating a simple To-Do app using Rails

ethand91

Ethan

Posted on June 16, 2022

Creating a simple To-Do app using Rails

Introduction

Hello! Just thought I'd show how to make a very simple todo app with Rails. ๐Ÿ˜ƒ


Installation

To start using Rails you will need to following installed:

  • Ruby
  • SQLite3

Installation will vary depending on the OS you're using so I recommend looking at the following guides:

Ruby: https://www.ruby-lang.org/en/documentation/installation/
SQLite3: https://www.sqlite.org/download.html

Then to install Rails you just need to run the following command:

gem install rails
Enter fullscreen mode Exit fullscreen mode

Creating the simple To-Do application

First we need to create the rails application, which can be done with the following command: (I've added some options because we don't need everything)

rails new todo --skip-action-mailer --skip-action-mailbox --skip-action-text --skip-active-storage --skip-action-cable
Enter fullscreen mode Exit fullscreen mode

If all goes well you should see a "todo" directory in the current workspace.

cd todo
Enter fullscreen mode Exit fullscreen mode

Next we will using generate to create the bolierplate code, which saves us having to write anything.
Using scaffold gives us a full set of model, database migration for that model, controller to manipulate it, views to view and manipulate the data and a test suite. In simple terms it does all the hard work for us. ๐Ÿ˜Ž

./bin/rails generate scaffold task content:text
Enter fullscreen mode Exit fullscreen mode

The above command creates a resource called task with one property called content which is of type text.

Next we need to create a database for the application, which can easily be done via the following command:

./bin/rails db:create
Enter fullscreen mode Exit fullscreen mode

Next we need to migrate the database which can be done via the following:

./bin/rails db:migrate
Enter fullscreen mode Exit fullscreen mode

Finally we just need to run the rails server.

./bin rails s
Enter fullscreen mode Exit fullscreen mode

Now if you navigate your browser to "http://localhost:3000/tasks", you should see the following page:

Tasks Page

If you click on "New task" it should take you to the following page where you can create a new task.

New Task

Feel free to try putting some text in and then click on "Create task", if successfull you should see that the task was created successfully.

New Task Created

Finally if you go back to the tasks page you should see the newly created task.

Tasks

You can also Edit and Delete tasks etc. Pretty simple UI put this is how you can implement a very simple todo app with Rails, also no code required ๐Ÿ˜„


Conclusion

Here I have shown how to create a very simple todo application with Rails with just the command line.
It's been a long time since I've used Rails, but hopefully this helps someone getting started with the Framework. ๐Ÿ˜€


Like me work? I post about a variety of topics, if you would like to see more please like and follow me.
Also I love coffee.

โ€œBuy Me A Coffeeโ€

๐Ÿ’– ๐Ÿ’ช ๐Ÿ™… ๐Ÿšฉ
ethand91
Ethan

Posted on June 16, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

ยฉ TheLazy.dev

About