Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 181 Vote(s) - 3.56 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Delete a record from console -- Ruby on Rails

#1
I want to delete a record from the console.

I logged through script/console and

User.find(1).delete
$<User id: 1, ..............>
User.find(1)
ActiveRecord::RecordNotFound: Couldn't find User with ID=1
........
........
........

Everything looks fine till here.

But when I exit the console and return back to console by script/console command, I am able again to see the record with id = 1.

The database is not local and I'm connecting through database.yml by giving an ip.

when I try to do the same on the development local database, everything is fine.

Can someone please explain whats happening and where am I missing!

Thanks
Reply

#2
Make sure you aren't invoking console in sandbox mode, which will prevent the delete operation.
Reply

#3
Easy way to remove Models data from console

rails console

Store user model to an instance variable

user = User.find(1)

delete or destroy the relations by following commands

user.delete
or

user.destroy






Reply

#4
On a similar note you can remove all the tuples for a given Object from the rails console as follows:

<!-- language: lang-rb -->

@object = Object.all

@object.each do |o|
o.delete
end

Reply

#5
Try

<!-- language: lang-rb -->

User.find(1).destroy

This should work in the console and otherwise.
Reply

#6
Try User.count or y User.count

User.first where first is the number you want to delete

User.first.destroy
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through