How to delete a DB data from the Ubuntu terminal? Ruby on Rails [closed]

-1

I made a scaffold in the rails ... OK. Now to using the paranoia gem to give a software delete, but there is that ta, how do I give the command for example of this, in a post of mine? Which way ...

    
asked by anonymous 29.12.2016 / 04:43

2 answers

1

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

  • Sign 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, then you type the   correct password and access the MySQL shell on the Linux terminal;

  • Make your queries as you wish:
  •   

    DELETE FROM% WITH_CORE% WHERE field="value";

        
    29.12.2016 / 06:28
    0

    I did not quite understand your question. But I'll post some ways to work with records.

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

    Change the "Post" for 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!

        
    30.12.2016 / 22:08