Rails 3 Authlogic acts_as_authentic undefined - ruby-on-rails

I'm getting an error that acts_as_authentic is undefined for rails 3, ruby 1.9.2
My Gemfile has: gem 'authlogic'
The command "bundle show authlogic" shows the correct path where authlogic is installed
My acts_as_authentic appears in a controller:
class User < ActiveRecord::Base
acts_as_authentic do |c|
c.login_field = :phone
end
end
Let me know if there's anything else that will be helpful, I'm new to rails so I'm not entirely sure what to post.
Thanks

For some reason I always ask questions on StackOverflow just before I figure it out. I needed to restart rails server to get it to work.

Related

getting error with has_secure_password in Rails 4

I am trying to use "has_secure_password" in my Rails project. I have included the bcrypt gem in my Gemfile and ran bundle install. However, when I run the project, I am getting the error below:
NameError in UsersController#index
undefined local variable or method `has_secure_pasword' for #<Class:0x00000004169e38>
User class
class User < ActiveRecord::Base
has_secure_pasword
validates :password, length: { minimum: 6 }
end
Any ideas on how to fix this?
I have not created any users - could that be the issue?
undefined local variable or method `has_secure_pasword' for
Class:0x00000004169e38
has_secure_pasword should be has_secure_password. You are missing a s in password.

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

Rails3 - oauth-plugin problem

I'm trying to use oauth-plugin on a Rails application I'm developing, but I keep running into problems.
To make sure I'm not making any mistake, I started an application from scratch (using Rails 3.0.3). Here are the steps I followed:
Create da new rails application (rails.test)
Edited its Gemfile to include:
gem "oauth-plugin", ">=0.4.0.pre1"
gem "oauth", "0.4.4"
Generated oauth-consumer, by running script/rails g oauth_consumer
Edited oauth_consumers.rb to include my keys for Google integration:
:google=>{
:key=>"anonymous",
:secret=>"anonymous",
:scope=>"https://www.google.com/calendar/feeds/",
:options => {
:site => "http://www.google.com",
:request_token_path => "/accounts/OAuthGetRequestToken",
:access_token_path => "/accounts/OAuthGetAccessToken",
:authorize_path=> "/accounts/OAuthAuthorizeToken"
},
}
Edited routes.rb to add the route for oauth_consumer:
resources :oauth_consumers
Edited application_controller.rb to implement the logged_in? method as follows:
def logged_in?
true
end
Now when I access http://localhost:3000/oauth_consumers/google I get the following error:
uninitialized constant GoogleToken
Does anyone know what causes this error and how can I fix it? GoogleToken is a class that should have been auto generated by oauth-plugin, so I can't tell why I'm getting this uninitialized constant error.
The GoogleToken class doesn't get auto-generated unless you pass "google" to the generator like so:
script/rails g oauth_consumer google
or for rails 3:
rails g oauth_consumer google
Also check to ensure the relationship is set up in the user model like so:
has_one :google, :class_name => "GoogleToken", :dependent => :destroy
Did you remember to run bundle install from terminal after editing your Gemfile? Sounds like your Rails app doesn't know about these gems yet.
I have the same problem, i think a solution could be in this:
https://github.com/pelle/oauth-plugin/blob/master/lib/generators/oauth_consumer/USAGE
You need some sort of authentication like restful-authentication plugin, if you uncomment line 27..29 in your oauth_consumers_controller.rb file, you'll jump to next step!

Rails validate_existence_of plugin

I'm reading the book Learning Rails by O'Reilly and it recommends using the validate_existence_of plugin. When I run:
ruby script/plugin install http: //svn.hasmanythrough.com/public/plugins/validates_existence/
it says it's already installed, but when I use it, I get a message saying:
NoMethodError in AwardsController#index
undefined method `validates_existence_of' for #<Class:0xb5fde868>
When I say:
class Award < ActiveRecord::Base
belongs_to :student
validates_existence_of :student
end
Any ideas?
Have you checked that the plugin code is installed in the vendor/plugins directory ?
Also you may need to check that the environment.rb file has the config.gem section uncommented.

Resources