Reputation: 87
I am having problems with the Rails runner. When I try to use if, even by command line, it does nothing! it doesn't show error messages, nor results from actions.
For example, if I try
rails runner Credit.count
having defined the model Credit
, and the method count as
Credit.first.update_attribute(:estado, "En proceso")
or even simpler tasks, the runner does nothing!
I've tried saying that the environment is development, but nothing works. Does anyone has any insights? Am I doing something wrong?
Edit: I am watching the database, that's the problem, there is no update. I changed the value of the column "estado" for the first element to something other than "En proceso", however, no matter how many times I use the runner, the db doesn't show any change at all.
Upvotes: 1
Views: 1862
Reputation: 87
Turns out I am an idiot.
First, I had to change the name of the method, calling Credit.count calls the default count method, so I changed it to myMethod.
After that, I was able to use puts function and update the database easily :)
Upvotes: 0
Reputation: 8821
rails runner: runner runs Ruby code in the context of Rails non-interactively
update_attribute : it only return true or false, if you want to output the result, you can use "puts" or "p".
For example,
$ rails r "User.first" #no output, even it will return a user object
$ rails r "puts User.first" # you can use "puts" get the output
#<User:0x007f8a2c76e608>
Upvotes: 2
Reputation: 2165
if you just written Credit.first.update_attribute(:estado, "En proceso")
in console, you shouldn't have results, but you could see result in DB, for checking if update_attribute
really update it you could write as update_attribute!
also you could just write:
p Credit.first.update_attribute(:estado, "En proceso")
which should print true
or false
to console
Upvotes: 0