Rails devise simple_form for signup doesn't validate before saving -


i have devise user signup using simple_form , i'm facing 2 issues:

issue 1:

if donot add '@ or .' in email, validation message flashed when press signup, conform email format , when giving validation message url still /user/signup.

but other fields - password , username there's length validate message, doesn't display same message conform username between 4...20 characters or password length. url changes /users , because user still not created if reload url browser, gives 500 error.

what should have validation message displayed , yet url not changed? thanks.

<%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name)) |f| %>   <%= f.error_notification %>   <div class="panel-body">     <%= f.input :email, required: '*', autofocus: true, label: false, placeholder: 'email', input_html: { class: 'input-md form-control' } %>     <%= f.input :username, required: true, label: false, placeholder: 'user name', input_html: { class: 'input-md form-control' } %>     <%= f.input :password, required: true, label: false, placeholder: 'password', input_html: { class: 'input-md form-control' } %>      <%= f.button :submit, "sign-up" %> </div> <% end %> 

customised devise registrations controller:

class mydevise::registrationscontroller < devise::registrationscontroller    def create     super     if !user.exists?(email: resource.email)       #to validate form before creating user        resource.valid? #first check if validation successful       resource.errors.messages.except!(:password) #remove password errors       if resource.save          redirect_to root_path, alert: "new user created"       else          #render root_path, alert: "there's problem saving profile database!"        end      end    end 

end

issue 2:

it registrations controller code above resource.valid? must validate , after goto save doesn't validate...why? so, flow comes save , i've comment 'else' part otherwise not display validation message. commenting 'else part of resource.save' not recommended.


Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -