How to delete a BD data from the Ubuntu terminal? Ruby on Rails

Asked

Viewed 300 times

-1

I scaffed the Rails... okay. Now I’m using Gem paranoia to give a software delete, but that’s it, how do I give the command for example this, in a post mine? Which way...

2 answers

1

To manipulate a Linux database through the terminal you just need to:

  1. Log in:

mysql -u root -p: "-u" to inform the user, which in this case is "root" and "-p" for Linux to display the password field, so you type the correct password and access the Mysql shell on the Linux terminal;

  1. Do your darlings as you wish:

DELETE FROM minha_tabela WHERE field = "value";

0

I don’t quite understand your question. But I will post some ways to work with records.

Enter your application folder with the terminal and type: Rails console

Change the "Post" to your model.

Post.delete_all #deleta todos os registros do model Post

Finding and removing records by id.

post = Post.find_by_id(5) # Encontra post de id 5 e armazena na variavel post

post.destroy #remove post

find_by can be used for other fields. Ex "title"

post = Post.find_by_title("Curso de Artes")

Vlw!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.