문제

I am looking up all Organizations with the url "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...

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top