Undefined method in Refinery::Blog while search enabling - ruby-on-rails

I enabled Refinery Search and Refinery Blog extensions in Gemfile and run rake db:migrate, rake db:seed.
And per Refinery Search instructions file, added the following to config/application.rb
config.to_prepare do
Refinery.searchable_models = [Refinery::Blog]
end
And also created app/decorators/models/refinery/blog_decorator.rb with
Refinery::Blog.class_eval do
acts_as_indexed :fields => [:title, :body, :custom_teaser]
end
Above example is from: http://refinerycms.com/guides/extending-model
But when I try to run rails c or rails s, there is an error:
=> Ctrl-C to shutdown server
Exiting
/home/bismailov/Desktop/my_docs/Inbox/ror/maqolarefinery/app/decorators/models/refinery/blog_decorator.rb:2:in `block in <top (required)>':
undefined method `acts_as_indexed' for Refinery::Blog:Module (NoMethodError)
from /home/bismailov/Desktop/my_docs/Inbox/ror/maqolarefinery/app/decorators/models/refinery/blog_decorator.rb:1:in `class_eval'
What could I be missing here? Thank you a lot!

Actually Refinery::Blog is a module not a model. Ideally you should use Refinery::Blog::Post.

Related

Where is db:create defined in Rails?

The following command is supposed to create a new database.
rails db:create
Where is this function defined? Or is this a pre-packaged function in rails?
It's in the databases.rake file of the framework:
namespace :create do
task all: :load_config do
ActiveRecord::Tasks::DatabaseTasks.create_all
end
ActiveRecord::Tasks::DatabaseTasks.for_each do |spec_name|
desc "Create #{spec_name} database for current environment"
task spec_name => :load_config do
db_config = ActiveRecord::DatabaseConfigurations.config_for_env_and_spec(Rails.env, spec_name)
ActiveRecord::Tasks::DatabaseTasks.create(db_config.config)
end
end
end
Whenever you doubt or want to know where a task has been defined, you can use the rails -W (or rake) command, passing the task:
$ rails -W db:create
rails db:create /path/databases.rake:26:in `block in <top (required)>'
rails db:create:all /path/databases.rake:20:in `block (2 levels) in <top (required)>'
Note it was introduced in the version 0.9 of Rake. This might or might not work depending on the versions which you're working with.

ActiveAdmin uninitialized constant - can not find the model

I install ActiveAdmin to my application. And register the model Order to ActiveAdmin
ActiveAdmin.register Order do
But I get the error uninitialized constant Order; it seems ActiveAdmin not found the model.
My Rails.root is
/home/vagrant/vag/shoppe-subao
the models is in:
/home/vagrant/vag/shoppe-subao/vendor/core/app/models/shoppe$ ls
order.rb
Start the rails server and get following error
=> Rails 4.0.1 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
/vagrant/shoppe-subao/vendor/core/app/models/shoppe/order
Exiting
/vagrant/shoppe-subao/app/admin/order.rb:3:in `<top (required)>': uninitialized constant Order (NameError)
from /home/vagrant/.bundler/ruby/2.2.0/active_admin-82da3c55cb61/lib/active_admin/application.rb:194:in `block in load'
Add require 'activeadmin' to your active_admin.rb initializer

Sidekiq Install - uninitialized constant ActiveRecord::Base (NameError)

I am trying to integrate Sidekiq with my Rails Mongoid app. I have been following the steps as outlined Here
I also have redis & mongodb running locally. However after I run bundle then when I try to start my server I get this error....
c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/sidekiq-2.17.7/lib/sidekiq/rails.rb:4:in `hook_rails!': uninitialized constant ActiveRecord::Base (NameError)
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/sidekiq-2.17.7/lib/sidekiq/rails.rb:16:in `block in <class:Rails>'
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:30:in `instance_exec'
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:30:in `run'
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:55:in `block in run_initializers'
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:54:in `each'
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:54:in `run_initializers'
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.13/lib/rails/application.rb:136:in `initialize!'
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.13/lib/rails/railtie/configurable.rb:30:in `method_missing'
from C:/Users/example/Documents/Workspace/app/config/environment.rb:5:in `<top (required)>'
My environment.rb file is as follows...
# Load the rails application
require File.expand_path('../application', __FILE__)
# Initialize the rails application
App::Application.initialize!
I previously had resque with redis working with mongoid in this app, so its a sidekiq issue. I don't have a database.yml file since I am using mongoid. I also added the steps for kiqstand but I am getting the same error. Unsure how to resolve?
Edit: I'm 90% sure its because Sidekiq is looking for ActiveRecord, however I removed ActiveRecord cause I'm using Mongo instead. My application.rb has...
# remove activerecord and run off of mongo only
#require 'rails/all'
#http://stackoverflow.com/a/9327651/1026266
%w(
action_controller
action_mailer
active_resource
rails/test_unit
sprockets
).each do |framework|
begin
require "#{framework}/railtie"
rescue LoadError
end
end
Now I just need to figure out how to tell sidekiq to not look for it?
Lack of ActiveRecord was the issue, looks like there was a pull request - https://github.com/mperham/sidekiq/pull/1090
But that was rejected, so I just had to add ActiveRecord to my app and add a dummy database.yml file.

RAILS : undefined method `secret_key=' for Devise:Module

I defined a model in rails using command rails generate model testdetails . After that I went to db/migrate and wrote the fields for this model
class CreateTestDetails < ActiveRecord::Migration
def self.up
create_table :test_details do |t|
t.column :TestName ,:string
t.column :TestType ,:integer
end
end
end
then i did db:migrate , it throws some error . I google it and found out that it may be coming due to devise version ( I am using devise for authentication) , I updated Gemfile and wrote the version of devise (2.1) and did bundle install . After that I again did db : migrate but it is showing this error
rake aborted!
undefined method secret_key=' for Devise:Module
/home/vibhor/rails_projects/recruit/config/initializers/devise.rb:7:inblock in '
/home/vibhor/rails_projects/recruit/config/initializers/devise.rb:3:in <top (required)>'
/home/vibhor/rails_projects/recruit/config/environment.rb:5:in'
Tasks: TOP => db:migrate => environment
what should i do so that this model can be created without any error? i am using rails 3.2.13 and ruby 2.0.0
I think this is due to gem version so update it to latest version 3.x or remove that line from your config/initializers/devise.rb file.
In your config/initializers/devise.rb file add this line:
config.secret_key = 'Your secret Key'
And use rake secret to generate your secret key.
There's an issue open in github if you need more info.
Had the same problems lately. Check devise initializers, as it has changed lately. For me it solved the problem.

Sunspot_Rails Rake Aborted When Running Reindex

I'm unable to index my database for searching with sunspot_rails. I get the following error:
Execute sunspot:reindex rake aborted!
undefined local variable or method
'counter'
I'm getting the following output after running rake sunspot:reindex. I'm a novice at Rails. I want to add sunspot_rails to my project to add search functionality (with the hope of deploying the project with Heroku).
I'm using Rails 3. I followed the instructions here: https://github.com/outoftime/sunspot/blob/master/sunspot_rails/README.rdoc. My various other attempts to diagnose the problem included:
installing sunspot in addition to sunspot_rails.
I ended up with sunspot_rails v. 1.2.0 and 1.2.1 so I uninstalled 1.2.1 because I have sunspot_rails 1.2.0.
installed the nokogiri gem which I understand is a dependency for sunspot_rails.
installed libxml2 separately following the instructions here to install nokogiri: http://www.engineyard.com/blog/2010/getting-started-with-nokogiri/
** Invoke sunspot:reindex (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute sunspot:reindex rake aborted! undefined local variable or method counter' for [removed pound]<Class:0x10359aef8> /Library/Ruby/Gems/1.8/gems/activerecord-3.0.3/lib/active_record/base.rb:1008:inmethod_missing' /Library/Ruby/Gems/1.8/gems/sunspot_rails-1.2.0/lib/sunspot/rails/searchable.rb:235:in solr_index' /Library/Ruby/Gems/1.8/gems/activerecord-3.0.3/lib/active_record/relation/batches.rb:71:infind_in_batches' /Library/Ruby/Gems/1.8/gems/activerecord-3.0.3/lib/active_record/base.rb:440:in __send__' /Library/Ruby/Gems/1.8/gems/activerecord-3.0.3/lib/active_record/base.rb:440:infind_in_batches' /Library/Ruby/Gems/1.8/gems/sunspot_rails-1.2.0/lib/sunspot/rails/searchable.rb:234:in solr_index' /Library/Ruby/Gems/1.8/gems/sunspot_rails-1.2.0/lib/sunspot/rails/searchable.rb:184:insolr_reindex' /Library/Ruby/Gems/1.8/gems/sunspot_rails-1.2.0/lib/sunspot/rails/tasks.rb:57 /Library/Ruby/Gems/1.8/gems/sunspot_rails-1.2.0/lib/sunspot/rails/tasks.rb:56:in each' /Library/Ruby/Gems/1.8/gems/sunspot_rails-1.2.0/lib/sunspot/rails/tasks.rb:56 /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:incall' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in execute' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:ineach' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in execute' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:ininvoke_with_call_chain' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/monitor.rb:242:in synchronize' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:ininvoke_with_call_chain' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in invoke' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:ininvoke_task' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in top_level' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:ineach' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in top_level' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:instandard_exception_handling' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in top_level' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:inrun' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in standard_exception_handling' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:inrun' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/bin/rake:31 /usr/bin/rake:19:in `load' /usr/bin/rake:19
This is what I have in class I'd like to search:
searchable do
text :fname
text :mname
text :lname, :default_boost => 2 end
Any help would be greatly appreciated!
The error is in the sunspot_rails-1.2.0/lib/sunspot/rails/searchable.rb:235 code.
You should fix it by yourself.
And fixing it is very easy:
def solr_index(opts={})
options = {
:batch_size => 500,
:batch_commit => true,
:include => self.sunspot_options[:include],
:first_id => 0
}.merge(opts)
if options[:batch_size]
counter = 1 #Add the variable
find_in_batches(:include => options[:include], :batch_size => options[:batch_size]) do |records|
solr_benchmark options[:batch_size], counter do
Sunspot.index(records)
end
Sunspot.commit if options[:batch_commit]
counter += 1 # Increase the variable
end
Sunspot.commit unless options[:batch_commit]
else
Sunspot.index!(all(:include => options[:include]))
end
end
Add counter variable in the front of find_in_batches, and increase it at the end of find_in_batches block.
And this variable is using for benchmark.
Don't worry~
Just to add a note, this is now fixed in Sunspot 1.2.1
That's a pretty timely intervention, user34.
Just installing Sunspot for Rails 3.0.1 running from Ubuntu 10.4. After first stumbling on connection problems with reindexing (Ubuntu users need to be sure they have Javascript running, it seems - sudo apt-get install default-jdk), I then ran into the same problem as Walter with 'counter'.
Is this a new Sunspot issue, I wonder?
Anyway, you posted your reply just a couple of hours before I needed it .. and as far as I can see, I look good to go now.
Thanks to both of you .. (and ALWAYS be wary of 5 minute installation claims :) )

Resources