相关疑难解决方法(0)

如何从Rake任务中运行Rake任务?

我已经编译在两个方面项目Rake文件,根据全局变量$build_type,它可以是:debug:release(结果走在不同的目录):

task :build => [:some_other_tasks] do
end
Run Code Online (Sandbox Code Playgroud)

我希望创建一个任务,依次编译项目的两个配置,如下所示:

task :build_all do
  [ :debug, :release ].each do |t|
    $build_type = t
    # call task :build with all the tasks it depends on (?)
  end
end
Run Code Online (Sandbox Code Playgroud)

有没有办法将任务称为方法?或者我怎样才能达到类似的效果呢?

ruby rake

402
推荐指数
5
解决办法
14万
查看次数

Rails rake 任务在生产中失败:“NoMethodError:为 URI:Module 调用私有方法‘open’”

我正在编写一个 rake 任务,它的功能是从其他网页获取信息。为此,我使用 open-uri 和 nokogiri。我已经在开发中进行了测试并且它可以完成工作,但是随后我部署到生产服务器并失败了。

这是代码:

require 'open-uri'
require 'nokogiri'

desc 'recover eventos llerena'
task recover_eventos_llerena: :environment  do

  enlaces = []

  # Getting index and all links
  url = open(URI.parse("https://llerena.org/eventos/lista"))
  page = Nokogiri::HTML(url)

  page.css("a.fusion-read-more").each do |line|
    enlaces.push(line.attr('href'))
  end

  enlaces = enlaces.uniq

  #Inspecting everyone of them
  enlaces.each do |link|
    url = open(URI.parse(link))
    page = Nokogiri::HTML(url)

    title = page.css("h1").text
    if Evento.find_by_titulo(title) == nil

      description = page.css(".tribe-events-single-event-description.tribe-events-content.entry-content.description p").text
      date = page.css(".tribe-events-abbr").attr('title')
      image = page.css(".size-full").attr('src')

      Evento.create!(
        titulo: title,
        remote_imgevento_url: image,
        info: description,
        fecha: …
Run Code Online (Sandbox Code Playgroud)

rake open-uri ruby-on-rails rake-task ruby-on-rails-5

2
推荐指数
2
解决办法
2256
查看次数