ruby on rails 4 - customizing devise routes for sign in and sign up -


i have sign-up , sign-in form on same page , want sign-up , sign-in errors such 'email exists' appear on page. i've customised registrations controller using this solution , created custom devisefailure class errors on sign in redirect page.

i have 2 questions:

  1. if sign fails due error in form (e.g. entering email address has been registered) , try sign in

    internal server error - inget, accepted http methods options, get, head, post, put, delete, trace, connect, propfind, proppatch, mkcol, copy, move, lock, unlock, version-control, report, checkout, checkin, uncheckout, mkworkspace, update, label, merge, baseline-control, mkactivity, orderpatch, acl, search, mkcalendar, , patch.

if reload redirect occurs correctly. dont know how address error.

  1. how trap errors sign in form or sign form? errors displaying twice - once each form.

routes.rb

  authenticated :user     root 'preorders#by_campaign', as: :authenticated_root   end    root to: 'users#index'    devise_for :users, :controllers => { :sessions => "sessions",                                    :passwords => "passwords",                                    :registrations => "registrations" } 

application_controller.rb

def after_sign_in_path_for(resource)   preorders_by_campaign_url end  def after_sign_out_path_for(resource)   root_url end 

registrations_controller.rb

class registrationscontroller < devise::registrationscontroller   protected    def after_sign_up_path_for(resource)     after_sign_in_path_for(resource)   end    def create     build_resource(sign_up_params)      if resource.save       yield resource if block_given?       if resource.active_for_authentication?         set_flash_message :notice, :signed_up if is_flashing_format?         sign_up(resource_name, resource)         respond_with resource, location: after_sign_up_path_for(resource)       else         set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_flashing_format?         expire_data_after_sign_in!         respond_with resource, location:    after_inactive_sign_up_path_for(resource)       end     else       clean_up_passwords resource       resource.errors.full_messages.each {|x| flash[x] = x} # rails 4 simple way       redirect_to root_path      end   end end 

index.rb

.user_form   %h2 sign    = form_for(resource, :as => resource_name, :url =>  registration_path(resource_name)) |f|    = render partial: "errors", locals: {flash: flash}      %div       = f.label :email        = f.email_field :email      %div       = f.label :password        = f.password_field :password      %div       = f.label :password_confirmation        = f.password_field :password_confirmation      %div= f.submit "sign up"   .user_form    %p signed up? sign in     = form_for(resource, :as => resource_name, :url => session_path(resource_name)) |f|       = render partial: "errors", locals: {flash: flash}      %div       = f.label :email        = f.email_field :email       %div        = f.label :password         = f.password_field :password       %div= f.submit "sign in" 

_errors.html.haml

-if flash.any?   %ul{class: "errors"}   - flash.each |msg|     %li=msg.first 


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -