A
A
Anton Misyagin2015-07-19 13:34:13
Ruby on Rails
Anton Misyagin, 2015-07-19 13:34:13

Worker in rails doesn't know the route?

Gemfile
gem 'resque', :require => 'resque/server'
routes.rb

get	'/товар/:id', :to => 'goods#show', :as => :good

class MyJob
  @queue = :my_job
  def self.perform
    g = Goods.where(:id => 1).first
    good_path(g),
  end
end

I can successfully use the good_path helper outside of the resque task, but here it gives an error:
undefined local variable or method `good_path' for MyJob:Class

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Anton Misyagin, 2015-07-20
@sunnmas

Try Rails.application.routes.url_helpers.good_path(g)
Thanks Andrey Nikiforov

A
Andrey Nikiforov, 2015-07-19
@eoffsock

include ActionDispatch::Routing::UrlFor
include ActionController::PolymorphicRoutes
include Rails.application.routes.url_helpers
default_url_options[:host] = 'example.com'

stackoverflow.com/questions/7732421/how-do-i-use-r...

D
Dmitry Kulikov, 2019-11-25
@Dimaon

Try good_url instead of good_path

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question