2010-10-22 27 views
5

Chúng tôi đã tạo ra một mô hình người dùng trong việc bắt đầu dự án, nhưng bây giờ (một số di chuyển sau này) chúng tôi muốn sử dụng đá quý. Có thể thêm suy nghĩ nếu mô hình người dùng và bảng đã tồn tại không? Nghĩa là, có thể thay đổi những gì đã được thực hiện hay chúng ta phải bắt đầu lại từ đầu?Có thể thêm ý tưởng, nếu mô hình người dùng đã tồn tại?

Trả lời

0

Tôi đã thực hiện. Đó là một chút đau đớn nhưng Devise xứng đáng với nó. Tạo một ứng dụng giả và thực hiện di chuyển. Sau đó, hãy xem schema.rb và viết một số di chuyển thực hiện tương tự với mô hình người dùng hiện tại của bạn.

Hoặc bạn có thể đọc qua nguồn và tìm hiểu những nơi như "database_authenticateable" được xác định. Bạn nên bắt đầu here.

4

Cavert Coder, nhưng:

(Lưu ý, này không di chuyển ": có thể khóa" bởi vì tôi không quan tâm về điều đó khi tôi đã viết nó này hiện nay bao gồm: có thể khóa vì MattSlay chăm sóc nhiều hơn tôi đã làm :). Ngoài ra, bạn cần di chuyển mật khẩu người dùng của mình vào trường mật khẩu được mã hóa. Cuối cùng, nó có thể không làm việc cho bạn. Xin lỗi)

class AddDevise < ActiveRecord::Migration 
    def self.up 
    null = false 
    default = "" 

    add_column :users, :encrypted_password, :string, :null => null, :default => default, :limit => 128 
    add_column :users, :password_salt, :string 
    add_column :users, :authentication_token, :string 
    add_column :users, :confirmation_token, :string 
    add_column :users, :confirmed_at,   :datetime 
    add_column :users, :confirmation_sent_at, :datetime 
    add_column :users, :reset_password_token, :string 
    add_column :users, :remember_token,  :string 
    add_column :users, :remember_created_at, :datetime 
    add_column :users, :sign_in_count,  :integer, :default => 0 
    add_column :users, :current_sign_in_at, :datetime 
    add_column :users, :last_sign_in_at, :datetime 
    add_column :users, :current_sign_in_ip, :string 
    add_column :users, :last_sign_in_ip, :string 

    #:lockable fields contributed by MattSlay 
    add_column :users, :failed_attempts, :integer, :default => 0 
    add_column :users, :unlock_token, :string 
    add_column :users, :locked_at, :datetime 

    end 

    def self.down 
    remove_column :users, :encrypted_password 
    remove_column :users, :password_salt 
    remove_column :users, :authentication_token 
    remove_column :users, :confirmation_token 
    remove_column :users, :confirmed_at 
    remove_column :users, :confirmation_sent_at 
    remove_column :users, :reset_password_token 
    remove_column :users, :remember_token 
    remove_column :users, :remember_created_at 
    remove_column :users, :sign_in_count 
    remove_column :users, :current_sign_in_at 
    remove_column :users, :last_sign_in_at 
    remove_column :users, :current_sign_in_ip 
    remove_column :users, :last_sign_in_ip 
    remove_column :users, :failed_attempts 
    remove_column :users, :unlock_token 
    remove_column :users, :locked_at 
    end 
end 
+0

Đã làm cho tôi! Bây giờ, phần này là gì: có thể khóa được? Tôi xem xét việc di chuyển Người dùng Devise và tôi chỉ thấy các trường bạn đã liệt kê. Tôi có thể tìm hiểu thêm về điều này ở đâu: điều có thể khóa? Tôi muốn triển khai lược đồ người dùng Devise đầy đủ. – MattSlay

+0

Ahh, tôi nghĩ rằng tôi đã tìm thấy các trường bắt buộc: có thể khóa. Tôi đã đăng chúng trong một câu trả lời riêng biệt bên dưới. – MattSlay

+0

Ah, tuyệt. Tôi đã tích hợp với một tệp lược đồ lớn ở trên. Cảm ơn bạn. – Aquarion

3

Ngoài các danh sách đó Aquarion cung cấp, tôi nghĩ rằng tôi đã tìm thấy ba lĩnh vực mà bạn cần nếu bạn muốn thực hiện:. Tùy chọn có thể khóa trên mô hình tài:

add_column :users, :failed_attempts, :integer, :default => 0 
add_column :users, :unlock_token, :string 
add_column :users, :locked_at, :datetime 
Các vấn đề liên quan