uninitialized constant Model::AlgoliaSearch - ruby-on-rails

I have an issue including Algolia module in my rails app
I have included gem "algoliasearch-rails", ran bundle install and added in config/initializers an algoliasearch.rb file with api id and key
#model.rb
include AlgoliaSearch
algoliasearch do
attribute :name, :description, :content, :is_public => true
end

I think you should restart your rails server ;)

Related

Rails 5 LoadError (cannot load such file -- roo)

I cannot seem to load roo and want to use it to import google spreadsheets
Im using rails 5.2.3, ruby 2.6.1p33
roo (2.8.2, 2.7.1)
Does anyone have an idea why this is happening?
When I try requiring roo in irb console, it seems to be working
class User < ApplicationRecord
has_secure_password
validates :username, presence: true, uniqueness: true
require 'roo'
def self.import(file)
spreadsheet = Roo::Spreadsheet.open(file.path)
end
end
Gemfile
gem "roo", "~> 2.8.0"
It's mostly an issue with your spring loader, run
bundle exec spring stop
bundle exec spring start

ENOENT Error in Serializer

I have just started working with rails and I encountered this error which does not give a lot of detail. Since I am not familiar with ruby on rails, perhaps someone here can help.
The error occurs in the active model serializer for the model.
class SecuritySerializer < ActiveModel::Serializer
attributes :id, :name, :ticker, :identifier, :weight
end
the rendering occurs as follows:
def index
#securities = Security.all
render(json: #securities, each_serializer: SecuritySerializer)
end
The error that I get:
Errno::ENOENT (No such file or directory # rb_sysopen - C):
app/serializers/security_serializer.rb:1:in `<top (required)>'
app/controllers/securities_controller.rb:9:in `index'
EDIT
I am using 64-bit ruby on windows 8.
I added this to a file called serializer_init.rb in config/initializers
ActiveModel::Serializer.config.adapter = :json_api
I was using version 0.10.0. I downgraded to 0.8.0 and removed the initializer. This solved the issue.
User gem from branch master.
gem 'active_model_serializers', :git => 'git://github.com/rails-api/active_model_serializers.git'

uninitialized constant Mongoid::Slug - can't get mongoid-slug to work

Receiving uninitialized constant Mongoid::Slug when trying to load a view.
The troubled Model is:
class Course
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::Slug
field :title, type: String
slug :title
validates :title, presence: true, uniqueness: true
end
Gemfile is pulling in mongoid and mongoid-slug as so:
gem 'mongoid', github: 'mongoid/mongoid', branch: 'master'
gem 'mongoid_search', '0.3.2'
gem 'mongoid-slug', github: 'digitalplaywright/mongoid-slug'
gem list shows the versions of each installed as:
mongoid (4.0.0)
mongoid-slug (4.0.0)
mongoid-tree (2.0.0)
mongoid_search (0.3.2)
Any suggestions as to what is occurring here?
All appears to have been resolved by restarting the dev environment.
Spun up the dev VM this morning and everything is happily playing along.
So perhaps after introducing mongoid-slug I should have just restarted the web server.

Rails Gem::LoadError in UsersController#new

New to Ruby on Rails and having a problem when following Michael Hartl's tutorial.I'm using Rails 3.2.2 with Ruby 1.9.3. The issue looks very similar to another question that was raised but was unanswered:
Rails Error NoMethodError in UsersController#show error
I get the following error when attempting to add a new user via /signup
Gem::LoadError in UsersController#new
bcrypt-ruby is not part of the bundle. Add it to Gemfile.
Reloading the page gives the error:
NoMethodError in UsersController#new
undefined method `key?' for nil:NilClass
The problem seems to be related to the inclusion of the bcrypt-ruby gem, and the usage of the has_secure_password method in user.rb . Removing the call to has_secure_password in user.rb gets rid of the error and it goes to the signup page successfully.
user.rb:
# == Schema Information
#
# Table name: users
#
# id :integer not null, primary key
# name :string(255)
# email :string(255)
# created_at :datetime not null
# updated_at :datetime not null
# password_digest :string(255)
#
class User < ActiveRecord::Base
attr_accessible :name, :email, :password, :password_confirmation
has_secure_password
validates :name, presence: true, length: { maximum: 50 }
valid_email_regex = /\A[\w+\-.]+#[a-z\d\-.]+\.[a-z]+\z/i
validates :email, presence: true,
format: { with: valid_email_regex },
uniqueness: { case_sensitive: false }
validates :password, length: { minimum: 6}
end
users_controller.rb:
class UsersController < ApplicationController
def new
#user = User.new
end
def create
#user = User.new(params[:user])
if #user.save
flash[:success] = "Welcome!"
redirect_to #user
else
render 'new'
end
end
end
However, I cant find anything wrong with the inclusion of the bcrypt-ruby gem. In the Gemfile I have:
gem 'bcrypt-ruby', '3.0.1'
and the gem has also been generated in Gemfile.lock :
DEPENDENCIES
annotate (~> 2.4.1.beta)
bcrypt-ruby (= 3.0.1)
I've also added password_digest to the database via migration:
class AddPasswordDigestToUsers < ActiveRecord::Migration
def change
add_column :users, :password_digest, :string
end
end
Any ideas ?
I'm going through the same tutorial and encountered the exact same problem.
My solution was to restart the web server. After installing the gem, I think the web server needs to be restarted so it is loaded.
Justin
Did you tried the 'bundle update' command, usually the bundler will take care of gems if you specified in the Gemfile. If you want to check the gem dependency please check http://rubygems.org/gems.
And if you are using windows(I know its strange- but some of our app works in windows only) there is some tricks to install bcrypt
Steps to install bcrypt.
1 Download Devkit and extract
you can download it from here http://rubyinstaller.org/downloads/
2 Place devkit it your jruby folder (in my case C:\applications\jruby\devkit)
3 You need to install ruby as well either 1.8.7 or 1.9(some times needs a system restart)
4 CD into devkit directory
5 Run ruby dk.rb init
6 Open config.yml and make sure that both your jruby installtion is listed. If not, ADD them. Save and close config.yml after you're done.
example:- C:/applications/jruby
7 Run ruby dk.rb install
8 jruby -S gem install bcrypt-ruby
Restarting the web server fixed it for me (had spork running in the background to speed up the running of the tests)

undefined local variable or method 'acts_as_gmappable'

I attempted to install the gmaps4rails gem.
I added gem 'gmaps4rails' to my Gemfile, and ran 'bundle install. It said that my bundle installed successfully. I can find "Using gmaps4rails (0.8.8)" with 'gem list'. I added the specified columns to my users table with rake db:migrate and added acts_as_gmappable and the gmaps4rails_address method to my User model.
Visiting pages that involve the user model gives me "undefined local variable or method 'acts_as_gmappable'"error.
Is there something that I am missing?
For greater context, the code I am using is from the Rails 3 Tutorial.
OS X 10.6.6
ruby 1.8.7
rails 3.0.7
passenger 3.0.7
Restarting the server should resolve the problem :)
I had the same issue : undefined local variable or method 'acts_as_gmappable'
I just restarted the server and it error went away.
I was using Mongoid and had the same trouble.
In which case, make sure your model includes:
include Gmaps4rails::ActsAsGmappable
acts_as_gmappable :position => :location
field :gmaps, :type => Boolean
field :location, :type => Array
def gmaps4rails_address
#describe how to retrieve the address from your model, if you use directly a db column, you can dry your code, see wiki
"#{self.address}, #{self.city}, #{self.country}"
end
I think this may be helpful (similar issue):
rvm + rails3 + gmaps4rails - acts_as_gmappable

Resources