Change development modules after the first generation

I study the rails. I found that Devise does a great job of connecting quickly and seamlessly to authentication, but I have one question.

How do I change modules after the first start of the Devise generator (for example, rails g devise User)? This default value has the following migration:

def self.up create_table(:users) do |t| t.database_authenticatable :null => false t.recoverable t.rememberable t.trackable # t.confirmable # t.lockable :lock_strategy => :failed_attempts, :unlock_strategy => :both # t.token_authenticatable t.timestamps end add_index :users, :email, :unique => true add_index :users, :reset_password_token, :unique => true # add_index :users, :confirmation_token, :unique => true # add_index :users, :unlock_token, :unique => true end 

If I started this migration, how to add or remove some of these modules at a later stage? For example. Perhaps I want to add a lock to an existing user model. I understand how to make changes to the model and devise.rb , but I'm not sure what to do with migrations.

Sorry, if the answer is already here, I drove a couple of hours here and google and did not find anything. Maybe I was looking for the wrong thing.

Thanks in advance! Jason
ps. I am using rails 3.0.0
develop 1.1.3

+7
ruby-on-rails ruby-on-rails-3 migration devise
source share
4 answers

Change the necessary lines in the migration file and repeat the migration according to these instructions:

http://guides.rubyonrails.org/migrations.html

0
source share

I was looking for the answer to the same question and, fortunately, I was next to someone who knew how to do this.

The following is an example of updating a user model to include a validated module using a script migration (script skeleton generated using the "rails generating the add_confirmable_to_users migration" ):

 class AddConfirmableToUser < ActiveRecord::Migration def self.up change_table :users do |t| t.confirmable end add_index :users, :confirmation_token, :unique => true end def self.down remove_column :users, :confirmable remove_index :users, :confirmation_token end end 
+6
source share

I was getting this error:

 undefined local variable or method `confirmed_at' for #<User:0x000001041531c8> (NameError) 

To add Confirmed -

Create Transfer:

 $ rails generate migration add_confirmable_to_users 

Change Migration:

 class AddConfirmableToUsers < ActiveRecord::Migration def change add_column :users, :confirmation_token, :string add_column :users, :confirmed_at, :datetime add_column :users, :confirmation_sent_at, :datetime add_column :users, :unconfirmed_email, :string end end 

http://guides.rubyonrails.org/migrations.html
https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.0-migration-schema-style

+2
source share

While you simply remove the options in which the corresponding fields have already been added to your schema (for example, confirmation), you can always simply edit the Users model directly without a new migration.

+1
source share

All Articles