Rails 3.2: Devise signup breaks when name or email not unique or email is fake (FriendlyID) -


edit: @vinodadhikary -- upon further investigation seems error happens when a) email not unique, b) name not unique or c) email fake (h@h.com). if devise isn't going accept signup prefer errors happen gracefully. error handling correct if passwords don't match or field isn't complete. also, non-unique names shouldn't problem? caused creation of slugs (using name slug) friendlyid?

original: i'm getting strange error on devise signup when signs when 1 of conditions above met signup. don't think i've done outside realm of normalcy devise installation (used rails composer, if matters). in advance help...

here error:

sqlite3::constraintexception: constraint failed: insert "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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,  ?, ?, ?, ?, ?, ?, ?, ?) 

devise/registrations/new.html.haml:

%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' }) |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:

class user < activerecord::base   rolify    # include default devise modules. others available are:   # :token_authenticatable, :confirmable,   # :lockable, :timeoutable , :omniauthable   devise :database_authenticatable, :registerable,          :recoverable, :rememberable, :trackable, :validatable, :confirmable    after_create :assign_default_role    # setup accessible (or protected) attributes 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 

full stack trace:

started post "/users" 127.0.0.1 @ 2013-07-17 19:20:23 -0400 processing devise::registrationscontroller#create html   parameters: {"utf8"=>"✓", "authenticity_token"=>"vl2a8qw8glcf7eljiqkw4fcbcrd7oaz1o9yjth3wg6g=", "user"=>{"name"=>"henry", "email"=>"h.h@gmail.com", "password"=>"[filtered]", "password_confirmation"=>"[filtered]"}, "commit"=>"join l"}    (0.1ms)  begin transaction   friendlyid::slug load (0.3ms)  select "friendly_id_slugs".* "friendly_id_slugs" "friendly_id_slugs"."sluggable_type" = 'user' , (slug = 'henry' or slug 'henry--%') order length(slug) desc, slug desc limit 1   user exists (0.1ms)  select 1 one "users" "users"."email" = 'h.h@gmail.com' limit 1   user load (0.1ms)  select "users".* "users" "users"."confirmation_token" = 'w6sjj2mz1wxqxefrfxym' limit 1 binary data inserted `string` type on column `encrypted_password`   sql (1.0ms)  insert "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", "h.h@gmail.com"], ["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 "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 "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" 127.0.0.1 @ 2013-07-17 19:20:23 -0400 

so friendlyid choking on creating multiple iterations of slug (got stuck after henry , henry--2, henry--3 throwing error) unknown reason. fixed issue changing slug attribute email, running find_each(&:save) clear out current slugs , doing same after returning slug name. fixed issue seems.

going forward going switch unique usernames because using names (which not have unique) ugly.

thanks @bdares , @vinodadhikary


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -