Skip to content

Spring can't run Rails server when developing an engine #323

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

Closed
davidmles opened this issue Jul 8, 2014 · 12 comments
Closed

Spring can't run Rails server when developing an engine #323

davidmles opened this issue Jul 8, 2014 · 12 comments

Comments

@davidmles
Copy link

Steps to reproduce:

rails plugin new example --mountable
cd example/
echo "gem 'spring'" >> Gemfile
bundle
echo "Spring.application_root = './test/dummy'" > config/spring.rb
bundle exec spring binstub --all

Trying to start the server from the engine directory:

example david$ spring rails s
Spring was unable to find your config/application.rb file. Your project root was detected at /Users/david/Sites/example, so spring looked for /Users/david/Sites/example/config/application.rb but it doesn't exist. You can configure the root of your application by setting Spring.application_root in config/spring.rb.

Trying to start the Rails console from the engine directory:

example david$ spring rails c
/Users/david/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/configuration.rb:37:in `pwd': No such file or directory - getcwd (Errno::ENOENT)
    from /Users/david/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/configuration.rb:37:in `project_root_path'
    from /Users/david/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/configuration.rb:28:in `application_root_path'
    from /Users/david/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/application.rb:243:in `loaded_application_features'
    from /Users/david/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/application.rb:105:in `ensure in preload'
    from /Users/david/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/application.rb:110:in `preload'
    from /Users/david/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/application.rb:140:in `serve'
    from /Users/david/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/application.rb:128:in `block in run'
    from /Users/david/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/application.rb:122:in `loop'
    from /Users/david/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/application.rb:122:in `run'
    from /Users/david/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/application/boot.rb:18:in `<top (required)>'
    from /Users/david/.rbenv/versions/2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /Users/david/.rbenv/versions/2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from -e:1:in `<main>'

Enter the dummy directory:

cd test/dummy/

Trying to start the Rails server using the rails bin file directly:

dummy david$ bin/rails s
Spring was unable to find your config/application.rb file. Your project root was detected at /Users/david/Sites/example, so spring looked for /Users/david/Sites/example/config/application.rb but it doesn't exist. You can configure the root of your application by setting Spring.application_root in config/spring.rb.

Trying to start the Rails server using Spring:

dummy david$ spring rails s
Spring was unable to find your config/application.rb file. Your project root was detected at /Users/david/Sites/example, so spring looked for /Users/david/Sites/example/config/application.rb but it doesn't exist. You can configure the root of your application by setting Spring.application_root in config/spring.rb.

Using Rails 4.1.4 and Ruby 2.1.2p95 on OS X Mavericks 10.9.4

@Irio
Copy link

Irio commented Oct 6, 2014

Experiencing the same issue on Rails 4.1.5 and Ruby 2.1.3p242.

Doing the following as said in the README does not seem to fix it.

$ cd <engine path>
$ echo "Spring.application_root = './spec/dummy'" > config/spring.rb

@heberuriegas
Copy link

+1, but is curious, the problem is only presented executing rails console

@fredmcgroarty
Copy link

i have the same issue as woohoou. This has only cropped up in the last few days

@itsterry
Copy link

Here's 2 ways that work for me. The first is nicer, but seems a little shaky. The second seems robust and quite quick but is hacky:

Method 1 - Nice but Flaky

Assuming that we're in the root of your engine, and your dummy app is in test/dummy:

In config/spring.rb, make sure you have the following:

  Spring.application_root='test/dummy'

And in test/dummy/config/spring.rb, make sure you have the following:

  Spring.application_root=''

To start your server:

cd test/dummy; rails s

To start your console:

cd test/dummy; rails c

Method 2 - Hacky but Steady

In config/spring.rb, make sure you have the following:

  Spring.application_root =File.expand_path(File.dirname(__FILE__)).gsub(/\/test\/dummy\/config/,'')+'/test/dummy'

And in test/dummy/config, make a symlink to that file:

cd test/dummy/config; ln -s ../../../config/spring.rb spring.rb

As I said: a bit hacky! :)

@davidmles
Copy link
Author

@itsterry none of those two methods work for me on Rails 4.2

Worth noting that with Rails 4.2 now the only thing not working is the server:

example david$ spring rails s
Spring was unable to find your config/application.rb file. Your project root was detected at /Users/david/Sites/example, so spring looked for /Users/david/Sites/example/config/application.rb but it doesn't exist. You can configure the root of your application by setting Spring.application_root in config/spring.rb.

The console and rake work:

example david$ spring rails c
Loading development environment (Rails 4.2.0)
example david$ spring rake -T
/Users/david/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/tasks/statistics.rake:4: warning: already initialized constant STATS_DIRECTORIES
/Users/david/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/tasks/statistics.rake:4: warning: previous definition of STATS_DIRECTORIES was here
rake app:about
...

@tvdeyen
Copy link

tvdeyen commented Jan 22, 2015

The 1. method from @itsterry works for me. Thanks.

@rjayroach
Copy link

For anyone who happens here and the above solutions don't work. I had the same error

spring rails s
Spring was unable to find your config/application.rb file. Your project root was detected at /Users/david/Sites/example, so spring looked for /Users/david/Sites/example/config/application.rb but it doesn't exist. You can configure the root of your application by setting Spring.application_root in config/spring.rb.

Running rails 4.2.4 on ruby 2.2.2p95.
The above solutions worked only partially. What did work was:

ENGINE_ROOT/config/spring.rb

Spring.applicaiton_root = 'spec/dummy'

With just that change, what worked was:

cd ENGINE_ROOT
spring rails c
spring rake -T

spring rails s still failed with above error.

How I got that working was:

cd ENGINE_ROOT/spec/dummy
touch Gemfile

Now from ENGINE_ROOT/spec/dummy: spring rails s

Without the empty Gemfile the error message was triggered from: https://github.com/rails/spring/blob/master/lib/spring/configuration.rb#L43

@tjcjc
Copy link

tjcjc commented Feb 18, 2016

  1. Add this code ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__) to the first line of spec/dummy/spring.
  2. Add Spring.application_root='spec/dummy' to config/spring.rb

@wkrsz
Copy link

wkrsz commented Jul 21, 2016

@tjcjc did you mean adding it to first line of spec/dummy/config/spring.rb, spec/dummy/.spring.rb or spec/dummy/bin/spring?

None of above worked for me, but running below command from spec/dummy did:

spec/dummy$ BUNDLE_GEMFILE=../../Gemfile rails s

@obromios
Copy link

obromios commented Feb 8, 2017

spec/dummy$ BUNDLE_GEMFILE=../../Gemfile rails s
worked for me.

@markdiginomad
Copy link

I solved this problem. My gemini duplicate program placed the config file in the trash, had to put back. Gemini - please fix this bug. Anyone has this problem check your config file.

@aaronjensen
Copy link

For those of you who have this working, does bin/rails g generate things in the right place?

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