This content originally appeared on DEV Community and was authored by Ethan
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
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.
cd todo
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:
./bin/rails db:create
Next we need to migrate the database which can be done via the following:
./bin/rails db:migrate
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 😄
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.
This content originally appeared on DEV Community and was authored by Ethan
Ethan | Sciencx (2022-06-16T07:09:37+00:00) Creating a simple To-Do app using Rails. Retrieved from https://www.scien.cx/2022/06/16/creating-a-simple-to-do-app-using-rails/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.