ruby - Rake task to update a column value -


i writing rake task update value in specific column in table. when run task, error:

uninitialized constant firstlooksubscription 

here rake task code:

namespace :first_look_db   desc "adds 1 month subscription"   firstsubscription.where(subscription_state: 'active').each |t|         t.update_attribute :next_billing_check, '2013-9-10'    end end 

i new rake tasks, , don't want migration. advice great!

also note: when run in rails console, executes without problem, biggest issue turning rake task our lead dev can run it

you need task name. namespace gives namespace of task, declare task name , import environment can find activerecords:

namespace :first_look_db   desc "adds 1 month subscription"    task :add_month_to_look_sub => :environment     firstsubscription.where(subscription_state: 'active').each |t|       t.update_attribute :next_billing_check, '2013-9-10'      end   end end 

this go file called lib/tasks/first_look_db.rake. task called by:

rake first_look_db:add_month_to_look_sub 

or possibly:

bundle exec rake first_look_db:add_month_to_look_sub 

if first 1 tells so. can name namespace , task wish in rake file. picked names seemed make sense me had.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -