Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uninitialized constant HighVoltage::StaticPage #146

Closed
cirdes opened this issue Jun 26, 2014 · 21 comments
Closed

uninitialized constant HighVoltage::StaticPage #146

cirdes opened this issue Jun 26, 2014 · 21 comments

Comments

@cirdes
Copy link

cirdes commented Jun 26, 2014

After upgrading from 2.1.0 to 2.2.0 this error started to appear.

initializers/high_voltage.rb


HighVoltage.configure do |config|
  config.route_drawer = HighVoltage::RouteDrawers::Root
  config.action_caching = true
  config.page_caching = true
  config.home_page = 'home'
  config.content_path = 'static/'
end

routes.rb

get "/*id" => "static#show", as: :page, format: false, constraints: HighVoltage::Constraints::RootRoute

static_controller.rb

class StaticController < ApplicationController
  include HighVoltage::StaticPage

  layout 'landpages'
end
@harlow
Copy link
Contributor

harlow commented Jun 26, 2014

Which version of Rails are you using?

It looks like your rails app is not picking up the include HighVoltage::StaticPage which is surprising because the initializer and routes are using HighVoltage as expected.

@cirdes
Copy link
Author

cirdes commented Jun 26, 2014

@harlow, I'm using rails 3.2.18 and ruby 2.0.0p481.

@harlow
Copy link
Contributor

harlow commented Jun 26, 2014

Can you try adding the layout to the config block?

HighVoltage.configure do |config|
  config.route_drawer = HighVoltage::RouteDrawers::Root
  config.action_caching = true
  config.page_caching = true
  config.home_page = 'home'
  config.content_path = 'static'
  config.layout = 'landpages'
end

Make sure to restart the server, and then comment out the line in the Routes file.

@cirdes
Copy link
Author

cirdes commented Jun 26, 2014

When I started the server I tried to access my page i got.

uninitialized constant HighVoltage::StaticPage

After hit reload i got:

The action 'show' could not be found for StaticController

This is happening every time I restart the server, downgrading to 2.1.0 makes high_voltage work fine.

@rossdakin
Copy link

Same issue.

@rossdakin
Copy link

Perhaps related to 2f99d07 ?

@harlow
Copy link
Contributor

harlow commented Jul 2, 2014

@rossdakin good eye. I think thats correct. I suspect this is an issue with Rails 4 vs Rails 4.1. Will experiment locally and see if I can reproduce.

@rossdakin
Copy link

@harlow thanks for looking into it – FWIW we're on Rails 3.2.18

@alexpchin
Copy link

Getting the routing issue with Rails 4.1.1

@dgalarza
Copy link
Contributor

I've been trying a similar configuration locally and haven't been able to reproduce this. Have you had a chance @harlow? Any luck?

@sgrif
Copy link

sgrif commented Jul 11, 2014

This is due to Rails autoloading being not thread-safe. Are you doing something that requests multiple HighVoltage pages at the same time, or close to it in development or test mode? (e.g. ajax requests?)

@sgrif
Copy link

sgrif commented Jul 11, 2014

The commit message at 2f99d07 would imply it was attempting to solve the issue there, as well. There's an undocumented method called require_dependency that we can use in place of require, which will hook into Rails' autoloading in a thread safe way, and act like a require outside of Rails.

@sgrif
Copy link

sgrif commented Jul 11, 2014

Also, this issue can be worked around by requiring the controller in an initializer.

@harlow
Copy link
Contributor

harlow commented Jul 14, 2014

@dgalarza I haven't been able to reproduce either using high_voltage (2.2.0). With vanilla Rails 4.1.0 and 4.1.1 everything works as expected.

@raphaelcm
Copy link

Just upgraded to 2.2.0. Getting the same error. Rails 3.2.18, Ruby 2.1.1.

Here's my initializer:

HighVoltage.configure do |config|
  config.content_path = 'content/'
  config.route_drawer = HighVoltage::RouteDrawers::Root
  config.action_caching = true
  config.page_caching = true
end

Upon first request of a static page, I get uninitialized constant HighVoltage::StaticPage. Second request, I get The action 'show' could not be found for HighVoltage::PagesController.

I tried requiring the controller in the initializer:

require 'high_voltage/pages_controller'

HighVoltage.configure do |config|
  config.content_path = 'content/'
  config.route_drawer = HighVoltage::RouteDrawers::Root
  config.action_caching = true
  config.page_caching = true
end

Then I just get the error on startup:

$ rails server
=> Booting WEBrick
=> Rails 3.2.18 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/Users/raphael/.rvm/gems/ruby-2.1.1/gems/high_voltage-2.2.0/app/controllers/high_voltage/pages_controller.rb:2:in `<class:PagesController>': uninitialized constant HighVoltage::StaticPage (NameError)

I'm not overriding anything -- totally vanilla HighVoltage setup.

Anything else I can do to get 2.2.0 to work? Or should I just downgrade?

@harlow
Copy link
Contributor

harlow commented Jul 19, 2014

@raphaelcm this may be a bit of a reach but could you also try requring the static page in the initializer too:

require 'concerns/high_voltage/static_page'
require 'high_voltage/pages_controller'

I suspect this is a Rails 3.x vs Rails 4.x issue because Rails 4 includes the concerns by default now.

@raphaelcm
Copy link

@harlow that worked, thanks!

@harlow
Copy link
Contributor

harlow commented Jul 20, 2014

@cirdes @rossdakin let me know if this works for you too. I'll get the README updated so its clear what people using Rails 3.x need to do.

harlow added a commit that referenced this issue Jul 20, 2014
We've been seeing some issues with Rails 3 applications unable to find
the `StaticPage` module.

* Add custom require for Rails 3

#146
harlow added a commit that referenced this issue Jul 20, 2014
We've been seeing some issues with Rails 3 applications unable to find
the `StaticPage` module.

* Add custom require for Rails 3
* Update quotes to match new style guide

#146
harlow added a commit that referenced this issue Jul 20, 2014
We've been seeing some issues with Rails 3 applications unable to find
the `StaticPage` module.

* Add custom require for Rails 3
* Update quotes to match new style guide

#146
@cirdes
Copy link
Author

cirdes commented Jul 20, 2014

I just upgraded my application to Rails 4, I'm not having that issue anymore. But thanks for your time.

@harlow
Copy link
Contributor

harlow commented Jul 20, 2014

OK great. Closing the issue.

I have a PR open that should fix the error for Rails 3 users: #155

@harlow harlow closed this as completed Jul 20, 2014
@rossdakin
Copy link

Awesome, thanks all. Haven't tested, but excited about the fix.

Any chance of revving a new gem with this in it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants