views:

580

answers:

2

I have the file config/initializers/custom.rb

In the file, there is only one line:

`rake thinking_sphinx:start`

I thought this was supposed to just execute the line like when typing it from a command line. With this line of code, when I run "ruby script/server", the server freezes and outputs no error messages. Am I missing something?

Thanks!

+4  A: 

Initializers load when your application loads. Rake tasks generally load your application. If you call a Rake task from an initializer, you're going to throw your app for a loop.

If you're worried about forgetting to start Sphinx in development, just give yourself a little warning:

# config/initializers/custom.rb
begin
  ThinkingSphinx::Search.search "test" # test search
rescue ThinkingSphinx::ConnectionError
  puts "** Oops! ThinkingSphinx is off! **"
end
stephencelis
eh...i like the idea, but stil buggy/vendor/plugins/thinking-sphinx/lib/thinking_sphinx/collection.rb:100:in `class_from_crc': You have a nil object when you didn't expect it! (NoMethodError)The error occurred while evaluating nil.constantize from /vendor/plugins/thinking-sphinx/lib/thinking_sphinx/collection.rb:79:in `instances_from_classes
Tony
Try changing from a blank search to "test" (blank searches have worked for me in the past when calling ModelName.search, but I guess things blow up when they're not scoped).
stephencelis
this works. i like this method too because i should probably be using a daemon manager plugin to manage the actual starting and stopping of daemons in production, but it is very nice to have a warning shoot off in dev mode. especially until i get around to setting up the daemon manager
Tony
A: 

I asked about how to get it to start up in dev mode via netbeans but the idea is the same. Bounty is still open.

My guess is that your not getting to the server starting because sphinx needs it's own process so it never returns to your custom initializer.

srboisvert
i thought about that as well, except when i run the rake task from the command line, the process is started in the background. so this should not be occuring
Tony