2013-07-18 1 views
0

편집 : thanks @vinodadhikary - 추가 조사시 오류가 발생했을 때 a) 이메일이 고유하지 않은 것, b) 이름이 고유하지 않거나 c) 전자 메일이 분명히 가짜입니다 ([email protected]). Devise가 가입을 수락하지 않으면 오류가 정상적으로 발생하는 것을 선호합니다. 암호가 일치하지 않거나 필드가 완료되지 않은 경우 오류 처리가 올 바릅니다. 또한 고유하지 않은 이름이 문제가되어서는 안됩니까? 이것은 FriendlyID와 함께 슬러그 (슬러그로 이름 사용)를 만들 때 발생합니까?Rails 3.2 : 이름이나 이메일이 고유하지 않거나 이메일이 가짜 인 경우 (FriendlyID)

원본 : 가입 조건에 위 조건 중 하나가 충족되면 누군가 가입 할 때 Devits 가입시 이상한 오류가 나타납니다. 나는 Devise 설치 (레일즈 컴포저 사용, 중요하다면)를 위해 정상적인 영역 밖에서 아무 것도하지 않았다고 생각합니다.

%section.row-fluid.sign-up 
    .container-fluid 
    .span6.landing-left 
     %h1 Sign Up! 
     .form-inputs 
     = simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => {:class => 'form-vertical' }) do |f| 
      = f.error_notification 
      = display_base_errors resource 
      = f.input :name, :autofocus => true, :placeholder => "Your Name", label: false 
      = f.input :email, :required => true, :placeholder => "Your Email", label: false 
      = f.input :password, :required => true, :placeholder => "Password", label: false 
      = f.input :password_confirmation, :required => true, :placeholder => "Password Confirmation", label: false 
      = f.button :submit, 'Join L', :class => 'btn button' 
     %p 
     = link_to "or, Sign In", new_user_session_url 

User.rb :

SQLite3::ConstraintException: constraint failed: INSERT INTO "users" 
("avatar_content_type", "avatar_file_name", "avatar_file_size", "avatar_updated_at", 
"confirmation_sent_at", "confirmation_token", "confirmed_at", "created_at",  
"current_sign_in_at", "current_sign_in_ip", "email", "encrypted_password", 
"fully_registered", "last_sign_in_at", "last_sign_in_ip", "name", "remember_created_at", 
"reset_password_sent_at", "reset_password_token", "sign_in_count", "slug", 
"unconfirmed_email", "updated_at") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 
?, ?, ?, ?, ?, ?, ?, ?) 

고안/등록/new.html.haml : 어떤 도움에 미리 감사드립니다 ... 여기

오류입니다

class User < ActiveRecord::Base 
    rolify 

    # Include default devise modules. Others available are: 
    # :token_authenticatable, :confirmable, 
    # :lockable, :timeoutable and :omniauthable 
    devise :database_authenticatable, :registerable, 
     :recoverable, :rememberable, :trackable, :validatable, :confirmable 

    after_create :assign_default_role 

    # Setup accessible (or protected) attributes for your model 
    attr_accessible :role_ids, :as => :admin 
    attr_accessible :name, :email, :password, :password_confirmation, :remember_me, :fully_registered, :avatar 

    has_one :profile, dependent: :destroy 

    has_many :appointments, foreign_key: "host_id" 
    has_many :appointments, foreign_key: "attendee_id" 

    has_many :reviews, foreign_key: "reviewee_id" 
    has_many :reviewed_users, foreign_key: "reviewer_id", class_name: "Review" 

    validates_attachment :avatar, 
          content_type: { content_type: ['image/jpeg', 'image/jpg', 'image/png', 'image/gif'] }, 
          size: { less_than: 1.megabytes } 


    extend FriendlyId 
    friendly_id :name, use: [:slugged, :history] 

    has_attached_file :avatar, styles: { 
    thumb: '100x100>', 
    square: '200x200#', 
    medium: '300x300>' 
    }, default_url: 'https://s3.amazonaws.com/l/layout/elements/placeholders/image_placeholder.svg' 


    def get_review_score 
    reviews.average('rating').to_f 
    end 

    protected 

    # def confirmation_required? 
    # false 
    # end 

    def assign_default_role 
    # Default Role: User, ID: 2 
    add_role(:user) 
    end 

end 

전체 스택 추적 :

Started POST "/users" for 127.0.0.1 at 2013-07-17 19:20:23 -0400 
Processing by Devise::RegistrationsController#create as HTML 
    Parameters: {"utf8"=>"✓", "authenticity_token"=>"Vl2A8qW8GLCF7elJIQkw4FCBcRd7Oaz1O9yJth3Wg6g=", "user"=>{"name"=>"Henry", "email"=>"[email protected]", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Join L"} 
    (0.1ms) begin transaction 
    FriendlyId::Slug Load (0.3ms) SELECT "friendly_id_slugs".* FROM "friendly_id_slugs" WHERE "friendly_id_slugs"."sluggable_type" = 'User' AND (slug = 'henry' OR slug LIKE 'henry--%') ORDER BY LENGTH(slug) DESC, slug DESC LIMIT 1 
    User Exists (0.1ms) SELECT 1 AS one FROM "users" WHERE "users"."email" = '[email protected]' LIMIT 1 
    User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."confirmation_token" = 'W6sjj2MZ1wxqxEfrFxYM' LIMIT 1 
Binary data inserted for `string` type on column `encrypted_password` 
    SQL (1.0ms) INSERT INTO "users" ("avatar_content_type", "avatar_file_name", "avatar_file_size", "avatar_updated_at", "confirmation_sent_at", "confirmation_token", "confirmed_at", "created_at", "current_sign_in_at", "current_sign_in_ip", "email", "encrypted_password", "fully_registered", "last_sign_in_at", "last_sign_in_ip", "name", "remember_created_at", "reset_password_sent_at", "reset_password_token", "sign_in_count", "slug", "unconfirmed_email", "updated_at") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [["avatar_content_type", nil], ["avatar_file_name", nil], ["avatar_file_size", nil], ["avatar_updated_at", nil], ["confirmation_sent_at", Wed, 17 Jul 2013 19:20:23 EDT -04:00], ["confirmation_token", "W6sjj2MZ1wxqxEfrFxYM"], ["confirmed_at", nil], ["created_at", Wed, 17 Jul 2013 19:20:23 EDT -04:00], ["current_sign_in_at", nil], ["current_sign_in_ip", nil], ["email", "[email protected]"], ["encrypted_password", "$2a$10$4XffwFcxoq4a8bDvUTvTauZNkUkKB/KgY.FZU4pxOH.pLmkL/JGvi"], ["fully_registered", false], ["last_sign_in_at", nil], ["last_sign_in_ip", nil], ["name", "Henry"], ["remember_created_at", nil], ["reset_password_sent_at", nil], ["reset_password_token", nil], ["sign_in_count", 0], ["slug", "henry--2"], ["unconfirmed_email", nil], ["updated_at", Wed, 17 Jul 2013 19:20:23 EDT -04:00]] 
SQLite3::ConstraintException: constraint failed: INSERT INTO "users" ("avatar_content_type", "avatar_file_name", "avatar_file_size", "avatar_updated_at", "confirmation_sent_at", "confirmation_token", "confirmed_at", "created_at", "current_sign_in_at", "current_sign_in_ip", "email", "encrypted_password", "fully_registered", "last_sign_in_at", "last_sign_in_ip", "name", "remember_created_at", "reset_password_sent_at", "reset_password_token", "sign_in_count", "slug", "unconfirmed_email", "updated_at") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) 
    (0.1ms) rollback transaction 
Completed 500 Internal Server Error in 81ms 

ActiveRecord::StatementInvalid - SQLite3::ConstraintException: constraint failed: INSERT INTO "users" ("avatar_content_type", "avatar_file_name", "avatar_file_size", "avatar_updated_at", "confirmation_sent_at", "confirmation_token", "confirmed_at", "created_at", "current_sign_in_at", "current_sign_in_ip", "email", "encrypted_password", "fully_registered", "last_sign_in_at", "last_sign_in_ip", "name", "remember_created_at", "reset_password_sent_at", "reset_password_token", "sign_in_count", "slug", "unconfirmed_email", "updated_at") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?): 
    activerecord (3.2.13) lib/active_record/connection_adapters/abstract_adapter.rb:285:in `rescue in log' 
    activerecord (3.2.13) lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log' 
    activerecord (3.2.13) lib/active_record/connection_adapters/sqlite_adapter.rb:242:in `exec_query' 
    activerecord (3.2.13) lib/active_record/connection_adapters/abstract/database_statements.rb:63:in `exec_insert' 
    activerecord (3.2.13) lib/active_record/connection_adapters/abstract/database_statements.rb:90:in `insert' 
    activerecord (3.2.13) lib/active_record/connection_adapters/abstract/query_cache.rb:14:in `insert' 
    activerecord (3.2.13) lib/active_record/relation.rb:66:in `insert' 
    activerecord (3.2.13) lib/active_record/persistence.rb:367:in `create' 
    activerecord (3.2.13) lib/active_record/timestamp.rb:58:in `create' 
    activerecord (3.2.13) lib/active_record/callbacks.rb:268:in `block in create' 
    activesupport (3.2.13) lib/active_support/callbacks.rb:414:in `_run__2609459987145809617__create__3448311305093244115__callbacks' 
    activesupport (3.2.13) lib/active_support/callbacks.rb:405:in `__run_callback' 
    activesupport (3.2.13) lib/active_support/callbacks.rb:385:in `_run_create_callbacks' 
    activesupport (3.2.13) lib/active_support/callbacks.rb:81:in `run_callbacks' 
    activerecord (3.2.13) lib/active_record/callbacks.rb:268:in `create' 
    activerecord (3.2.13) lib/active_record/persistence.rb:348:in `create_or_update' 
    activerecord (3.2.13) lib/active_record/callbacks.rb:264:in `block in create_or_update' 
    activesupport (3.2.13) lib/active_support/callbacks.rb:425:in `_run__2609459987145809617__save__3448311305093244115__callbacks' 
    activesupport (3.2.13) lib/active_support/callbacks.rb:405:in `__run_callback' 
    activesupport (3.2.13) lib/active_support/callbacks.rb:385:in `_run_save_callbacks' 
    activesupport (3.2.13) lib/active_support/callbacks.rb:81:in `run_callbacks' 
    activerecord (3.2.13) lib/active_record/callbacks.rb:264:in `create_or_update' 
    activerecord (3.2.13) lib/active_record/persistence.rb:84:in `save' 
    activerecord (3.2.13) lib/active_record/validations.rb:50:in `save' 
    activerecord (3.2.13) lib/active_record/attribute_methods/dirty.rb:22:in `save' 
    activerecord (3.2.13) lib/active_record/transactions.rb:259:in `block (2 levels) in save' 
    activerecord (3.2.13) lib/active_record/transactions.rb:313:in `block in with_transaction_returning_status' 
    activerecord (3.2.13) lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction' 
    activerecord (3.2.13) lib/active_record/transactions.rb:208:in `transaction' 
    activerecord (3.2.13) lib/active_record/transactions.rb:311:in `with_transaction_returning_status' 
    activerecord (3.2.13) lib/active_record/transactions.rb:259:in `block in save' 
    activerecord (3.2.13) lib/active_record/transactions.rb:270:in `rollback_active_record_state!' 
    activerecord (3.2.13) lib/active_record/transactions.rb:258:in `save' 
    devise (2.2.4) app/controllers/devise/registrations_controller.rb:15:in `create' 
    actionpack (3.2.13) lib/action_controller/metal/implicit_render.rb:4:in `send_action' 
    actionpack (3.2.13) lib/abstract_controller/base.rb:167:in `process_action' 
    actionpack (3.2.13) lib/action_controller/metal/rendering.rb:10:in `process_action' 
    actionpack (3.2.13) lib/abstract_controller/callbacks.rb:18:in `block in process_action' 
    activesupport (3.2.13) lib/active_support/callbacks.rb:436:in `_run__1922468707363096533__process_action__814005644436315713__callbacks' 
    activesupport (3.2.13) lib/active_support/callbacks.rb:405:in `__run_callback' 
    activesupport (3.2.13) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks' 
    activesupport (3.2.13) lib/active_support/callbacks.rb:81:in `run_callbacks' 
    actionpack (3.2.13) lib/abstract_controller/callbacks.rb:17:in `process_action' 
    actionpack (3.2.13) lib/action_controller/metal/rescue.rb:29:in `process_action' 
    actionpack (3.2.13) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action' 
    activesupport (3.2.13) lib/active_support/notifications.rb:123:in `block in instrument' 
    activesupport (3.2.13) lib/active_support/notifications/instrumenter.rb:20:in `instrument' 
    activesupport (3.2.13) lib/active_support/notifications.rb:123:in `instrument' 
    actionpack (3.2.13) lib/action_controller/metal/instrumentation.rb:29:in `process_action' 
    actionpack (3.2.13) lib/action_controller/metal/params_wrapper.rb:207:in `process_action' 
    activerecord (3.2.13) lib/active_record/railties/controller_runtime.rb:18:in `process_action' 
    actionpack (3.2.13) lib/abstract_controller/base.rb:121:in `process' 
    actionpack (3.2.13) lib/abstract_controller/rendering.rb:45:in `process' 
    actionpack (3.2.13) lib/action_controller/metal.rb:203:in `dispatch' 
    actionpack (3.2.13) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch' 
    actionpack (3.2.13) lib/action_controller/metal.rb:246:in `block in action' 
    actionpack (3.2.13) lib/action_dispatch/routing/route_set.rb:73:in `dispatch' 
    actionpack (3.2.13) lib/action_dispatch/routing/route_set.rb:36:in `call' 
    actionpack (3.2.13) lib/action_dispatch/routing/mapper.rb:42:in `call' 
    journey (1.0.4) lib/journey/router.rb:68:in `block in call' 
    journey (1.0.4) lib/journey/router.rb:56:in `call' 
    actionpack (3.2.13) lib/action_dispatch/routing/route_set.rb:612:in `call' 
    warden (1.2.1) lib/warden/manager.rb:35:in `block in call' 
    warden (1.2.1) lib/warden/manager.rb:34:in `call' 
    actionpack (3.2.13) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call' 
    rack (1.4.5) lib/rack/etag.rb:23:in `call' 
    rack (1.4.5) lib/rack/conditionalget.rb:35:in `call' 
    actionpack (3.2.13) lib/action_dispatch/middleware/head.rb:14:in `call' 
    actionpack (3.2.13) lib/action_dispatch/middleware/params_parser.rb:21:in `call' 
    actionpack (3.2.13) lib/action_dispatch/middleware/flash.rb:242:in `call' 
    rack (1.4.5) lib/rack/session/abstract/id.rb:210:in `context' 
    rack (1.4.5) lib/rack/session/abstract/id.rb:205:in `call' 
    actionpack (3.2.13) lib/action_dispatch/middleware/cookies.rb:341:in `call' 
    activerecord (3.2.13) lib/active_record/query_cache.rb:64:in `call' 
    activerecord (3.2.13) lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call' 
    actionpack (3.2.13) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call' 
    activesupport (3.2.13) lib/active_support/callbacks.rb:405:in `_run__2361827533017433596__call__3448311305093244115__callbacks' 
    activesupport (3.2.13) lib/active_support/callbacks.rb:405:in `__run_callback' 
    activesupport (3.2.13) lib/active_support/callbacks.rb:385:in `_run_call_callbacks' 
    activesupport (3.2.13) lib/active_support/callbacks.rb:81:in `run_callbacks' 
    actionpack (3.2.13) lib/action_dispatch/middleware/callbacks.rb:27:in `call' 
    actionpack (3.2.13) lib/action_dispatch/middleware/reloader.rb:65:in `call' 
    actionpack (3.2.13) lib/action_dispatch/middleware/remote_ip.rb:31:in `call' 
    better_errors (0.9.0) lib/better_errors/middleware.rb:84:in `protected_app_call' 
    better_errors (0.9.0) lib/better_errors/middleware.rb:79:in `better_errors_call' 
    better_errors (0.9.0) lib/better_errors/middleware.rb:56:in `call' 
    actionpack (3.2.13) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call' 
    actionpack (3.2.13) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call' 
    railties (3.2.13) lib/rails/rack/logger.rb:32:in `call_app' 
    railties (3.2.13) lib/rails/rack/logger.rb:16:in `block in call' 
    activesupport (3.2.13) lib/active_support/tagged_logging.rb:22:in `tagged' 
    railties (3.2.13) lib/rails/rack/logger.rb:16:in `call' 
    quiet_assets (1.0.2) lib/quiet_assets.rb:18:in `call_with_quiet_assets' 
    actionpack (3.2.13) lib/action_dispatch/middleware/request_id.rb:22:in `call' 
    rack (1.4.5) lib/rack/methodoverride.rb:21:in `call' 
    rack (1.4.5) lib/rack/runtime.rb:17:in `call' 
    activesupport (3.2.13) lib/active_support/cache/strategy/local_cache.rb:72:in `call' 
    rack (1.4.5) lib/rack/lock.rb:15:in `call' 
    actionpack (3.2.13) lib/action_dispatch/middleware/static.rb:63:in `call' 
    railties (3.2.13) lib/rails/engine.rb:479:in `call' 
    railties (3.2.13) lib/rails/application.rb:223:in `call' 
    rack (1.4.5) lib/rack/content_length.rb:14:in `call' 
    railties (3.2.13) lib/rails/rack/log_tailer.rb:17:in `call' 
    rack (1.4.5) lib/rack/handler/webrick.rb:59:in `service' 
    /usr/local/rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service' 
    /usr/local/rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run' 
    /usr/local/rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread' 



Started POST "/__better_errors/70311741936300/variables" for 127.0.0.1 at 2013-07-17 19:20:23 -0400 
+0

삽입하려는 이메일 주소는 고유합니까? – vee

+0

고맙습니다 @vinodadhikary, 위의 내 주요 게시물을 편집했습니다 ... – henry

+0

는 DB 제약이있는 것 같습니다. 어떻게 테이블을 만들었습니까? (마이그레이션 내용은 무엇입니까?) – bdares

답변

0

그래서 FriendlyId는 알 수없는 몇 가지 이유 때문에 특정 슬러그 (henry and henry - 2, henry - 3가 오류를 던진 후 붙어있어)를 반복적으로 만드는 것에 질식했습니다. 나는 슬러그 속성을 전자 메일로 변경하고 find_each (& : 저장)를 실행하여 현재 슬러그를 지우고 슬러그를 이름으로 되 돌린 후 동일한 작업을 수행하여이 문제를 해결했습니다. 이로 인해 문제가 해결되었습니다.

앞으로 (고유 할 필요는없는) 이름이 너무 추악하기 때문에 고유 한 사용자 이름으로 전환 할 예정입니다.

도움 주셔서 감사합니다. @bdares 및 @vinodadhikary