Rails 3 link_to 耙任务 [英] Rails 3 link_to rake task

查看:56
本文介绍了Rails 3 link_to 耙任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中创建了一个 rake 任务,现在我希望应用程序用户可以通过菜单上的链接访问该任务,但我不知道如何从那里调用它.像这样……?

I've created a rake task in my application and now I want the task to be accesible for app users from a link on a menu, but I don't know how to invoke it from there. Something like this...?

<%= link_to t('backup'), Rake::Task['backup'].invoke %>

推荐答案

你不能这样做.Link_to 可以链接到静态或控制器动作.因此,您需要创建一些操作,您可以在其中调用您的 Rake 任务.

You can't do it. Link_to can link to something static or controller action. So you need to create some action, where you can invoke your Rake Task.

class MyTasksController < ApplicationController 
  def rake_it
    Rake::Task['backup'].invoke
  end
end

<%= link_to  t("backup"), {:controller => :my_tasks, :action => "rake_it"} %>

这篇关于Rails 3 link_to 耙任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆