Rails migration error database_authenticatable - ruby-on-rails

-- create_table(:admin_users)
rake aborted!
An error has occurred, this and all later migrations canceled:
undefined method `database_authenticatable' for #
Tasks: TOP => db:migrate
How to solv it? Thanx!
migration
create_table(:admin_users) do |t|
t.database_authenticatable :null => false
t.recoverable
t.rememberable
t.trackable
t.timestamps
end
have all gems in gemfile and installed

Make sure you have devise in the Gemfile and the bundle is installed.

Answer is simple device team sucks!!!
to solve this need make cnanges in GEMFILE
gem 'devise', "~> 1.5"
because in 1.5 there is database_authenticatable type support and in 2.1.0 there is support of only compatibility not creation of fields with this type
thanx everybody.

If you're just getting started with devise (vs updating from previous verions), you might have missed the following step before doing rake db:migrate
rails generate devise:install
This creates
create config/initializers/devise.rb
create config/locales/devise.en.yml
which define the method rake is complaining about above.
Source:
https://github.com/plataformatec/devise

With Devise 2.0 and newer, the migration helper methods (t.database_authenticatable for example) are not available (as stated on the wiki here ) If you're making a new model for users, just use the devise migration generator like so:
rails g devise admin_users (If you're installing devise on your app)
If you're adding the required fields to an existing user model, you should check this page on the devise wiki.
Check out the main README for devise, which has up-to-date information for installing the latest version of devise on Rails.

Related

Active_admin running an error when run rake db:migrate

I'm trying to install ActiveAdmin under Rails 4 to generate my admin panel.
I added the gem and installed with the below commands:
gem 'activeadmin', github: 'gregbell/active_admin'
bundle install
rails g active_admin:install # creates the AdminUser class
rails g active_admin:install User # uses an existing class
But when I try to migrate I get an error:
$ rake db:migrate
== AddDeviseToAdminUsers: migrating ==========================================
-- change_table(:admin_users)
rake aborted!
An error has occurred, this and all later migrations canceled:
SQLite3::SQLException: duplicate column name: email: ALTER TABLE "admin_users" ADD "email" varchar(255) DEFAULT '' NOT NULL/usr/local/rvm/gems/ruby-2.0.0-p247/gems/sqlite3-1.3.8/lib/sqlite3/database.rb:91:in `initialize'
As mentioned in issue 753 on github I changed the AddDeviseToAdminUsers migration from change_table to create_table but that results in this error:
== AddDeviseToAdminUsers: migrating ==========================================
-- create_table(:admin_users)
rake aborted!
Can anyone help please?
The exception you're seeing is due to a migration conflicting with your existing database structure. Your admin_users table already contains an "email" column, which is why you're seeing the error duplicate column name: email.
You should only run the active_admin:install generator once. Running the ActiveAdmin setup with a clean application should only involve the following:
# Add the BETA gem with Rails 4 support. The ActiveAdmin master
# branch is still in heavy development.
gem 'activeadmin', github: 'gregbell/active_admin'
# Bundle
bundle install
# Setup ActiveAdmin
rails g active_admin:install
For more advanced cases, where you already have an ActiveRecord model for an admin user then you'd use this variant of the generator: rails g active_admin:install MyAdminUser

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.

Rails - can't make database migration on Heroku for app using Devise authentication

My application uses Devise authentication gem.
When i do
rake db:migrate
locally, everything is going well, but when I do this on Heroku:
heroku run rake db:migrate --app myappname
I get
rake aborted!
uninitialized constant Devise::Encryptors::Base
Tasks: TOP => db:migrate => environment
(See full trace by running task with --trace)
I have no Idea what could go wrong.
I run into the same issue because I implemented a custom encryptor. Since version 2.1 of devise custom encryptors have been extracted to a separate gem. To get it working do the following.
Add the devise-encryptable gem to your Gemfile.
gem 'devise-encryptable'
Subclass from Devise::Encryptable::Encryptors::Base instead of Devise::Encryptors::Base.
# lib/devise/encryptors/md5.rb
require 'digest/md5'
module Devise
module Encryptable
module Encryptors
class Md5 < Base
def self.digest(password, stretches, salt, pepper)
str = [password, salt].flatten.compact.join
Digest::MD5.hexdigest(str)
end
end
end
end
end
I updated the how-to page of devise as well. I hope this solves your problem.

rails migration version issue: any new migration not working

From this morning, I am facing weird issues with Rails devise. Following is output of my ls and rake db version command.
hrishikesh#hrishikesh-ubuntu:~/git-public/personaldiary/db/migrate$ ls -1
20120110083934_devise_create_users.rb
20120110090514_create_posts.rb
20120110090845_add_user_id_to_post.rb
20120203035323_add_confirmable_to_devise.rb
20120203035323_add_confirmable_to_devise.rb~
20120203043601_add_lockable_to_devise.rb
20120203043601_add_lockable_to_devise.rb~
hrishikesh#hrishikesh-ubuntu:~/git-public/personaldiary/db/migrate$ rake db:version
(in /home/hrishikesh/git-public/personaldiary)
DEPRECATION WARNING: require "activerecord" is deprecated and will be removed in Rails 3. Use require "active_record" instead. (called from /usr/lib/ruby/vendor_ruby/activerecord.rb:2)
Current version: 20120203034555
hrishikesh#hrishikesh-ubuntu:~/git-public/personaldiary/db/migrate$
If I try to add any new migrations, rake db:migrate throws error that tells me that some column already exists, and fails.
My failing migration code is here:
class AddConfirmableToDevise < ActiveRecord::Migration
def change
change_table(:users) do |t|
t.confirmable
end
add_index :users, :confirmation_token, :unique => true
end
end
I specifically do not want to use up and down methods because of this
Please help.
After spending hours to find solution, I decided to give up and ran
rake db:migrate:reset
And it worked, only thing is my data was lost, which was not that big deal at this point.
Thank you everyone for attempting to solve this.

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