Field update, best practice

Hi everybody… I’m stuck with a strange (stupid) problem I can’t
understand.

I’m trying to do this in the articles_controller:

def updatecollection
@arts = Article.find_by_solr(“14 MAY 91”).results

@arts.each do |doc|
  @sub = doc.title[15,150]
   # Updating one record:
   doc.title = @sub
  doc.save

end

end

It loads but i doesn’t update the article…the strange fact is that if
I do the same process for a single doc in the console it works… so
what’s wrong? something in the .each do?
thanks!

(any different solution it’s fine for me :wink: )

2010/1/25 adedip [email protected]:

  # Updating one record:
  doc.title = @sub
 doc.save

Test the return value from save here to see if it succeeded. Perhaps
it is failing validation.

Colin

My Guess is that try eliminating the results
@arts = Article.find_by_solr(“14 MAY 91”).results
from this and try using
@arts = Article.find_by_solr(“14 MAY 91”)

On 25 Gen, 16:57, Colin L. [email protected] wrote:

@arts.each do |doc|
@sub = doc.title[15,150]
# Updating one record:
doc.title = @sub
doc.save

Test the return value from save here to see if it succeeded. Perhaps
it is failing validation.

Colin

but I get true doing it on console…could it be different on the app
controller?
anyway how do i test it? something like:

if doc.save
puts “true”

?

thx

2010/1/25 adedip [email protected]:

but I get true doing it on console…could it be different on the app
controller?
anyway how do i test it? something like:

if doc.save
puts “true”

No, have a look at the Rails Guide on debugging. There are various
options, I would use ruby-debug and break in at that point.

Colin

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs