开发者

How to .strip all emails in a rails database?

I have a batch invite command where users can enter a bunch of emails to invite people to an account in my app. However, up until now, it was including one space at the front of every e-mail...

I've since added a .strip for every new email, but I now want to update all previously created accounts.

I am running the app on heroku,开发者_运维百科 so I'd imagine it will be a command at the heroku console, I just don't want to feck it up, so I'm asking for help here.

Nevermind, I figured it out.

     User.all.each do |user|; user.update_attributes(:email => user.email.split); end

That was the solution. Just a little tricky figuring out that Heroku only works with one line at a time, unlike the actual rails console.


If you can execute SQL via the rails console. Try

begin; update users set email = trim(email); commit;

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜