Rails - Help with rake task
Posted
by
jyoseph
on Stack Overflow
See other posts from Stack Overflow
or by jyoseph
Published on 2010-12-29T01:46:42Z
Indexed on
2010/12/29
1:53 UTC
Read the original article
Hit count: 657
I have a rake task I need to run in order to sanitize (remove forward slashes) some data in the database. Here's the task:
namespace :db do
desc "Remove slashes from old-style URLs"
task :substitute_slashes => :environment do
puts "Starting"
contents = Content.all
contents.each do |c|
if c.permalink != nil
c.permalink.gsub!("/","")
c.save!
end
end
puts "Finished"
end
end
Which allows me to run rake db:substitute_slashes --trace
If I do puts c.permalink
after the gsub! I can see it's setting the attribute properly. However the save! doesn't seem to be working because the data is not changed. Can someone spot what the issue may be?
Another thing, I have paperclip installed and this task is triggering [paperclip] Saving attachments.
which I would rather avoid.
© Stack Overflow or respective owner