resque / resque-web

a Rails-based web interface to Resque
235 stars 166 forks source link

Error undefined method 'root_path' for ActionDispatch::Routing::RoutesProxy #132

Closed charneykaye closed 6 years ago

charneykaye commented 6 years ago

Created a new Rails 5.0.6 app, added this engine. The line in question is supposed to "just work" insofar as a Rails engine ought to be able to use main_app.root_path to refer to the app home.

But here it "just doesn't work"

ActionView::Template::Error (undefined method `root_path' for #<ActionDispatch::Routing::RoutesProxy:0x00007f66be1d4a80>):
    46:             <%= tab tab_name,path %>
    47:           <% end %>
    48:           <% if respond_to?(:main_app) %>
    49:             <li><%= link_to "Return to Application", main_app.root_path, :class => "nav navbar-nav" %></li>
    50:           <% end %>
    51:         </ul>
    52:       </div>

config/routes.rb:

require "resque_web"

Rails.application.routes.draw do
  get '/', to: 'home#index', as: :home

  mount ResqueWeb::Engine => "/resque", :as => 'resque_web'
end

config/resque.yml

development: redis01xx1:6379
production: 10.1.5.106:6379

config/initializers/resque.rb

rails_root = ENV['RAILS_ROOT'] || File.dirname(__FILE__) + '/../..'
rails_env = ENV['RAILS_ENV'] || 'development'

resque_config = YAML.load_file(rails_root + '/config/resque.yml')
Resque.redis = resque_config[rails_env]
charneykaye commented 6 years ago

Answer was simply that I had failed to add root :to => 'home#index' to my routes.

Fixed config/routes.rb:

require "resque_web"

Rails.application.routes.draw do
  root :to => 'home#index'

  get '/', to: 'home#index', as: :home

  mount ResqueWeb::Engine => "/resque", :as => 'resque_web'
end