开发者

Writing a simple conditional statement in IRB

I am looking up all Organizations with the url 开发者_如何学C"http://", and updating their attributes to "".

My attempt:

Organization(:all).select { |o| o.url = "http://" ? o.update_attribute("url","")}

Which returns a compile error:

SyntaxError: compile error
 (irb):2: syntax error, unexpected '}'
   from (irb):2

Any ideas?


Try using update_all

Organization.update_all("url = ''", ["url =?",'http://'])


I'm by no means a ruby expert, but my first suspicion is that you're using an assignment operator (=) instead of an equality operator (==). A quick google search for "ruby irb conditional" appears to prove this.

And you probably got the down vote because you did not include compilation errors in your question. If my guess is wrong, I can't even help try to interpret the error message, because you didn't provide it.

UPDATE: based on the first comment to the answer, I believe my first suspicion to be wrong - a misinterpretation of the intent of the line of code. But, then, this is what happens when error messages are not availble.

UPDATE2: first comment not there... maybe it was deleted or maybe I started typing in the wrong place...

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜