0

I'm using devise. I modified the user fields with no problem. I need to access certain users, and modify their info. For example, let's say that the user "pete" should have the field "type" changed to "active". How do I do that? it should be just accessing the database and modify that field, but I can't make it work. I mean, there are tools to modify databases, but what is the rails way to do it?

I don't need a tool or script or modify the code, it's a small database and very few changes. Once I understand this, I may do something more general.

cauchi
  • 1,463
  • 2
  • 17
  • 45
  • Just a small warning: don't use 'type' as a column name, or read this thread: http://stackoverflow.com/questions/7134559/rails-use-type-column-without-sti – cthulhu Jul 22 '13 at 11:19

2 Answers2

0

The typical rails way to operate on your data like this is to write custom rake tasks. The great Ryan Bates has a great screencast on the topic as well: http://railscasts.com/episodes/66-custom-rake-tasks.

If you do not want to do that, and the fixes you are making are really small, then you can do them via the rails console. More on that here: http://railsonedge.blogspot.in/2008/05/intro-to-rails-console.html

pungoyal
  • 1,768
  • 15
  • 17
0

If you need the actual code of how to do that, it may look like this:

pete = User.find_by_name('pete')
pete.update_attributes(:type, 'active')
Konstantin Rudy
  • 2,237
  • 25
  • 22