CONSOLE TIP → DELETE THE DATABASE FROM TERMINAL RUBY ON RAILS

Eveline Szoda
3 min readSep 16, 2020

Hey! I would like to show you an easy way to delete any data from your database using a terminal. I will show you in the example of my app: Construction Manager. My App has back-end Ruby on Rails and front-end React. The app allows me to create the meeting but I can not delete it from the frontend. I did not create a delete button.

Have a look!

Let’s create a meeting clicking a button “ADD MEETING” and …

… fill in the needed information.

We are going to create the meeting by clicking the button “CREATE MEETING”, which will show up on the page straight away.

Let’s go back to our database. Go to your terminal, find the directory where is your backend and go to console using command rails c.

By running the command Meeting.all we are going to see all meetings in our database.

To see the last created meeting we need to run Meeting.last

Now we need to name that meeting following the line below. In our case, the meeting calls meeting_to_delete.

Now we can use the name meeting_to_delete to identify the object(our meeting) and use function destroy to delete the meeting from the database. You can notice now that, Meeting.last is not anymore meeting_to_delete. This is my way to double-check if we permanently deleted the object.

Let’s back to our front-end to check if the meeting is not there anymore…

Viola!!! All done correctly :)

More console tip for Ruby on Rails you can find here

Hope you enjoy the post!

Happy coding!

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Eveline Szoda
Eveline Szoda

Written by Eveline Szoda

Full Stack Developer with a true passion for making great ideas come true.

No responses yet

Write a response