twillw
twillw

Reputation: 64

run rake task with button

I wrote rake tasks in my rails apps to fetch information for a list of products from another website. I want to add the functionality to click a button on my products page that will run the rake tasks and update. So far I've added an action to my ProductsController:

def get_info
  system "rake fetch_prices &"
  flash[:notice] = "Fetching info for Products"
  redirect_to index_url
end 

Then my index view has:

<%= link_to "Get info", my_rake_task_path, :method => 'put' %>

As for the route I'm stumped. Based on other tutorials I added:

put 'rake_task' to: 'productscontroller#get_info' :as 'my_rake_task'

Then I get an error in the routes file when I try to start up the server.

Upvotes: 2

Views: 1944

Answers (1)

BvuRVKyUVlViVIc7
BvuRVKyUVlViVIc7

Reputation: 11811

Rake::Task['task_name'].invoke

Upvotes: 6

Related Questions