I'm trying to use sunspot with Rails 4 and I'm running into some issue. When I have only gem 'sunspot_rails', '2.0.0' in my gemfile I get this error:
Note: This task has been moved to the sunspot_solr gem. To install, start and
stop a local Solr instance, please add sunspot_solr to your Gemfile:
group :development do
gem 'sunspot_solr'
end
But when I add that gem(also v 2.0.0) I get this error:
rake aborted!
Don't know how to build task 'sunspot:solr:start'
/home/toasty/.rvm/gems/ruby-2.0.0-p195/bin/ruby_noexec_wrapper:14:in `eval'
/home/toasty/.rvm/gems/ruby-2.0.0-p195/bin/ruby_noexec_wrapper:14:in `<main>'
(See full trace by running task with --trace)
I have seen this question:
Sunspot/Solr raketasks not loading in Rails 3 Mountable Engine
but it doesn't seem to work in my case. Does anyone have any ideas? Is sunspot_solr just not compatible with rails 4?
I had this same problem. I don't recall but I found this rake task that you need to add
lib/tasks/solr.rake
namespace :sunspot do
namespace :solr do
desc 'Start the Solr instance'
task :start => :environment do
case RUBY_PLATFORM
when /w(in)?32$/, /java$/
abort("This command is not supported on #{RUBY_PLATFORM}. " +
"Use rake sunspot:solr:run to run Solr in the foreground.")
end
if defined?(Sunspot::Rails::Server)
Sunspot::Rails::Server.new.start
else
Sunspot::Solr::Server.new.start
end
puts "Successfully started Solr ..."
end
desc 'Run the Solr instance in the foreground'
task :run => :environment do
if defined?(Sunspot::Rails::Server)
Sunspot::Rails::Server.new.run
else
Sunspot::Solr::Server.new.run
end
end
desc 'Stop the Solr instance'
task :stop => :environment do
case RUBY_PLATFORM
when /w(in)?32$/, /java$/
abort("This command is not supported on #{RUBY_PLATFORM}. " +
"Use rake sunspot:solr:run to run Solr in the foreground.")
end
if defined?(Sunspot::Rails::Server)
Sunspot::Rails::Server.new.stop
else
Sunspot::Solr::Server.new.stop
end
puts "Successfully stopped Solr ..."
end
# for backwards compatibility
task :reindex => :"sunspot:reindex"
end
end
EDIT~ Source of Rakefile
Related
I'm building a gem with a list of rake tasks. I have this:
#/lib/tasks/my_gem.rake:
namespace :my_gem do
task :task1 do
puts "Hello"
end
end
I install the gem to a rails application and run rake -T. And there's no task "task1" or anything related to "my_gem".
Add a description, like so:
namespace :my_gem do
desc "my task"
task :task1 do
puts "Hello"
end
end
I have just added the seed-fu gem to my app for seeding my test-database:
group :test do
gem 'seed-fu'
end
I made a custom rake task (in /lib/tasks/db.rake) for seeding only my test-database:
namespace :db do
desc "seed_fu only in test-database"
task seed_fu_test: :environment do
Rails.env = 'test'
puts "Seeding will be made in test-base ONLY!"
Rake::Task["db:seed_fu"].execute
end
end
If I do rake -T | grep seed then my new custom-made task is shown amongst other seed-tasks:
rake db:seed # Load the seed data from db/seeds.rb
rake db:seed_fu # Loads seed data for the current environment
rake db:seed_fu_test # seed_fu only in test-database
Now when I do rake db:seed_fu_test I get
rake aborted!
Don't know how to build task 'db:seed_fu'
But when I do
rake db:seed_fu RAILS_ENV='test'
then seed_fu seeds my test-database well.
Figured it out- the problem was in my Gemfile. Because I added the seed-fu gem into test-group then in development-environment, which was my default for running also the rake db:seed_fu_test task, the seed_fu gem was not seen.
Therefore when moving gem 'seed-fu' line into my :development-group in Gemfile, the problem was solved.
I'm actually trying to install and use the Sunspot gem for Rails (https://github.com/sunspot/sunspot). So far here is what I did. I added the dependencies in my Gemfile :
gem 'sunspot_rails'
gem 'sunspot_solr'
Then I did run bundle and create the configuration file using rails generate sunspot_rails:install. So far so good.
But then, when I tried to run bundle exec rake sunspot:solr:start, I'm facing the following error :
rake aborted!
Don't know how to build task 'sunspot:solr:start'
/Users/project/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task_manager.rb:49:in `[]'
/Users/project/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:148:in `invoke_task'
/Users/project/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/Users/project/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:106:in `each'
/Users/project/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:106:in `block in top_level'
/Users/project/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:115:in `run_with_threads'
/Users/project/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:100:in `top_level'
/Users/project/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:78:in `block in run'
/Users/project/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:165:in `standard_exception_handling'
/Users/project/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:75:in `run'
/Users/project/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/bin/rake:33:in `<top (required)>'
/Users/project/.rbenv/versions/2.0.0-p247/bin/rake:23:in `load'
/Users/project/.rbenv/versions/2.0.0-p247/bin/rake:23:in `<main>'
I'm actually using Rails 4 and Ruby 2.0.0. Did anyone already face the same issue or know a way to fix that?
Thanks a lot for the help
I had the same error that I was able to solve by adding the following file.
Source of Rakefile
Duplicate Question
lib/tasks/solr.rake
namespace :sunspot do
namespace :solr do
desc 'Start the Solr instance'
task :start => :environment do
case RUBY_PLATFORM
when /w(in)?32$/, /java$/
abort("This command is not supported on #{RUBY_PLATFORM}. " +
"Use rake sunspot:solr:run to run Solr in the foreground.")
end
if defined?(Sunspot::Rails::Server)
Sunspot::Rails::Server.new.start
else
Sunspot::Solr::Server.new.start
end
puts "Successfully started Solr ..."
end
desc 'Run the Solr instance in the foreground'
task :run => :environment do
if defined?(Sunspot::Rails::Server)
Sunspot::Rails::Server.new.run
else
Sunspot::Solr::Server.new.run
end
end
desc 'Stop the Solr instance'
task :stop => :environment do
case RUBY_PLATFORM
when /w(in)?32$/, /java$/
abort("This command is not supported on #{RUBY_PLATFORM}. " +
"Use rake sunspot:solr:run to run Solr in the foreground.")
end
if defined?(Sunspot::Rails::Server)
Sunspot::Rails::Server.new.stop
else
Sunspot::Solr::Server.new.stop
end
puts "Successfully stopped Solr ..."
end
# for backwards compatibility
task :reindex => :"sunspot:reindex"
end
end
You might want to try updating your version of the sunspot_solr gem, in case Rubygems is giving you an older version of sunspot_solr by mistake.
Try adding this to your gemfile instead of gem 'sunspot_solr' and running the bundle install + bundle exec rake sunspot:solr:start:
gem 'sunspot_solr', '~> 2.0.0', group: :development
ENV
Rails 3.2.13
ruby 1.9.3p392
airbrake 3.1.11
rake, version 10.0.4
my config file and rake task file
#lib/tasks/raise.rake
namespace :raise do
desc "raise sth"
task :sth => :environment do
num = 1 / 0 # should raise error
end
end
end
# config/initializers/airbrake.rb
Airbrake.configure do |config|
config.rescue_rake_exceptions = true
config.api_key = Setting.airbrake_api
end
I hope run RAILS_ENV=production rake raise:sth send message to my airbrake, but nothing happen, just output divided by 0, not anything call stack info.
please help me, thank you ~
I'm using the friendly_id gem.
There's a rake task for deleting old slugs (from the docs):
rake friendly_id:remove_old_slugs MODEL=<model name> DAYS=<days>
It can be run via cron.
Do you know how it should be added to cron.rake (I'm on Heroku)?
Here is my cron.rake:
desc "This task is called by the Heroku cron add-on"
task :cron => :environment do
...
rake friendly_id:remove_old_slugs
end
It produces an error:
"rake aborted! undefined method `friendly_id' for main:Object"
There is no error if I run it from the console (Terminal) like this:
heroku rake friendly_id:remove_old_slugs
Try this:
desc "This task is called by the Heroku cron add-on"
task :cron => :environment do
Rake::Task['friendly_id:remove_old_slugs'].execute
end