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

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.

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

I am Using mongodb in rails and when use the carrierwave gem this thrown errors

I am using the following commond
gem 'carrierwave'
bundle
rails generate uploader image
mount_uploader :image, ImageUploader
but it gives the errors
NoMethodError in PostsController#index
undefined method `mount_uploader' for Post:Class Extracted source
(around line #8):
line #8: mount_uploader :image, ImageUploader
end
I think your problem is you are using the wrong gem, for mongodb using mongoid ORM you should use the following gem,
gem 'carrierwave-mongoid', :require => 'carrierwave/mongoid'
If you install this you problem should get solved.

uninitialized constant Model::AlgoliaSearch

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 ;)

What changed in Ruby?

The following spec passes fine in Ruby 2.1.5 but fails in 2.2.0 and I can't tell what that's all about:
# job.rb
class Job < ActiveRecord::Base
validates :link, :url => true
end
# job_spec.rb
require 'rails_helper'
describe Job do
describe "#create" do
["blah", "http://", " "].each do |bad_link|
it {
should_not allow_value(bad_link).for(:link)
}
end
end
end
fail log looks like this:
1) Job#create should not allow link to be set to "http://"
Failure/Error: should_not allow_value(bad_link).for(:link)
Expected errors when link is set to "http://",
got no errors
# ./spec/models/job_spec.rb:14:in `block (4 levels) in <top (required)>'
I find the only way to for that spec to pass with Ruby 2.2.0 is to include the validates_url gem in my project!!
Does anyone know this is about?
Maybe my solution isn't ideal, but it works.
Replace validates_url gem by validates gem. It has UrlValidator (written by me), which is well tested.
gem 'validates' # in Gemfile
validates :link, :url => true # you needn't to change something. Just remove validates_url from your Gemfile
P.S. It's a strange way - to test functionality of gem. Functionality should be tested in gem already.
P.P.S. I'm strongly recommend you to move to ruby 2.2.1 (or 2.2.2) instead of 2.2.0, because of 2.2.0 has a lot of bugs

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)

Resources