Hello! Just thought I'd show how to make a very simple todo app with Rails. 😃
To start using Rails you will need to following installed:
Installation will vary depending on the OS you're using so I recommend looking at the following guides:
Then to install Rails you just need to run the following command:
gem install rails
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
If all goes well you should see a "todo" directory in the current workspace.
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
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:
Next we need to migrate the database which can be done via the following:
Finally we just need to run the rails server.
./bin rails s
Now if you navigate your browser to "http://localhost:3000/tasks", you should see the following page:
If you click on "New task" it should take you to the following page where you can create a 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.
Finally if you go back to the tasks page you should see the newly created task.
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 😄
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.
Top comments (2)
Impressive! Thank you for sharing!
No problem! Hope it helps :D