Question

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?

Was it helpful?

Solution

Try using update_all

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

OTHER TIPS

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...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top