Referring to update_all in http://api.rubyonrails.org/,
I managed to get the job done with the following script.
The only time I relied on using find (which does have return records
set to readonly) is when I had to get the live status object out.
Aside from that, it's easier on the db hits.

 Thank you, everyone esp Franz!

------------------ script/publish_blog_entries.rb - Start
---------------------

class Blog < ActiveRecord::Base
    live_status = Status.find_by_name('live')
    live_status_sql_clause = "status_id = " + live_status.id.to_s

    Blog.update_all( live_status_sql_clause, "status_id not in
( select id from statuses where name in ('published', 'archived') )" )
end

------------------ script/publish_blog_entries.rb - End
---------------------

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to