I'm working on my login page with the Devise Gem. I encounter this weird thing when i click on the buttons. The messages displays itself at the end of the former one instead of replacing it. Do you know the potential reason of this strange behavior? Thanks a lot!
My session/new.rb
<h2>Log in</h2>
<%= simple_form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
<div class="form-inputs">
<%= f.input :email,
required: false,
autofocus: true,
input_html: { autocomplete: "email" } %>
<%= f.input :password,
required: false,
input_html: { autocomplete: "current-password" } %>
<%= f.input :remember_me, as: :boolean if devise_mapping.rememberable? %>
</div>
<div class="form-actions">
<%= f.button :submit, "Log in" %>
</div>
<% end %>
<%= render "users/shared/links" %>
A picture of the render in the browser
login page
I tried to find where i can limit this behaviour but unfortunately i didn't found it.
When you login unsuccessfully.
It will render flash
Ex: flash[:alert] = "You need to sign in ...."
After that, in application.html.erb display this error
<p class="notice"><%= notice %></p>
<p class="alert"><%= alert %></p>
Make sure notice and alert in front of <%= yield %> and no repeat alert or notice
Related
Without making a custom Sessions controller that inherits from the hidden devise controller, I want to figure out a way of adding the parameter, "g-recaptcha-response" to be included in the authenticating process from the default devise view.
Here's my view with the recaptcha figure included. When I click on it I do get a response when my app calls the SessionController#create method. I'm trying to figure out how to make this process detect that the captcha form has been clicked and authenticates the user logging in because of it.
<h2>Log in</h2>
<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true, autocomplete: "email" %>
</div>
<div class="field">
<%= f.label :password %><br />
<%= f.password_field :password, autocomplete: "off" %>
</div>
<% if devise_mapping.rememberable? -%>
<div class="field">
<%= f.check_box :remember_me %>
<%= f.label :remember_me %>
</div>
<% end -%>
<div class="g-recaptcha" data-sitekey="6LeeL5gUAAAAADbq0vt4d9biAs8oegkPx9ttUkKb"></div>
<div class="actions">
<%= f.submit "Log in" %>
</div>
<% end %>
<%= link_to 'Sign Up', new_user_registration_path %>
In essence, if a bot were to attempt automatically signing in repeatedly, the devise controller would see that the captcha was not clicked and stops them from trying to log in.
I am building a movies website. I would like the home page (views/movies/index.html.erb) to display a list of all movies even to visitors who are not signed in. And I would like to provide a login link on the home page which when clicked should invoke the authentication system of devise gem. How do I achieve this?
I provide this link on the home page (views/movies/index.html.erb)
<%= link_to 'Log in', login_path, :class => "btn btn-primary" %>
I have this in my routes.rb file:
get 'login', to: 'devise#new', as: 'login'
I have provided this dummy method in movies_controller.rb
def login
end
This is the new session (login) code generated by devise in /views/devise/sessions/new.html.erb
<header>
<h1>
Log in
</h1>
</header>
<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
<%= f.label :email %> <%= f.email_field :email, autofocus: true, class: "form-control" %>
<%= f.label :password %> <%= f.password_field :password, autocomplete: "off", class: "form-control" %>
<% if devise_mapping.rememberable? -%>
<%= f.check_box :remember_me %> Remember Me
<% end -%> <%= f.submit "Log in", class: "btn btn-primary btn-lg" %>
<% end %>
<%= render "devise/shared/links" %>
If I somehow invoke /views/devise/sessions/new.html.erb, would that solve my problem?
If yes, then how can I invoke this erb from movies_controller?
If no, then how else can I solve my login problem?
I can't display devise errors. The problem happen only in sign up page. However the configuration for sign in and sign up is the same...
I display errors via the application.html.erb
I know the errors are properly generated because when I put resource.errors.full_messages at the beginning, errors are displaying. But without the style I made.
sign up
.section
.subscribe-c.w-container
.section-title-group
h2.heading Bonjour !
= simple_form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f|
= f.input_field :email, class: "form-field w-input", placeholder: "Email"
= f.input_field :password, class: "form-field w-input", placeholder: "Mot de passe", html: { autocomplete: 'off' }
= f.input_field :password_confirmation, class: "form-field w-input", placeholder: "Confirmez votre mot de passe", html: { autocomplete: 'off' }
= f.submit "Je m'inscris", class: "button full-width w-button"
= render "devise/shared/links"
sign in (the one who works properly)
.section
.subscribe-c.w-container
.section-title-group
h2.heading Bonjour !
= simple_form_for(resource, as: resource_name, url: session_path(resource_name)) do |f|
= f.input_field :email, class: "form-field w-input", placeholder: "Email"
= f.input_field :password, class: "form-field w-input", placeholder: "Mot de passe", html: { autocomplete: 'off' }
= f.submit "c'est parti !", class: "button full-width w-button"
= render "devise/shared/links"
application.html.erb
<body class=body>
<% if notice %>
<p class="alert alert-success"><%= notice %></p>
<% end %>
<% if alert %>
<p class="alert alert-danger"><%= alert %></p>
<% end %>
<%= render 'layouts/navbar' %>
<%= yield %>
</body>
It appears that the correct translation is missing: "Courriel translation missing: fr.activerecord.errors.models.user.attributes.email.blank.
Here is a list of all French translations from Devise: https://github.com/plataformatec/devise/wiki/I18n#french-devisefryml
Make sure you set your configuration appropriately based on the documentation towards the top.
Also if you are looking for specific ActiveRecord translations you can look at the rails-i18n gem where you can find more French translations here.
It's because you're using f.input_field which tells simpleform to strip away all divs around the form field. If you switch to f.input, simpleform will wrap your fields in the div that Rails will look to add the error messages to. This may break some of your styling since now all form fields will have an extra div wrapper but you can always then make your own custom error messages at the top of the form. Ex.
<% if #some_object.errors.any? %>
<ul>
<% #some_object.errors.each do |error,msg| %>
<li> <%=error.capitalize%> <%=msg%></li>
<% end %>
</ul>
<% end %>
<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
<% if alert %>
<p class="alert alert-danger"><%= alert %></p>
<% end %>
<div>
<%= f.email_field :email, autofocus: true, placeholder: 'Correo Electrónico' %>
</div>
<div class="m-t">
<%= f.password_field :password, autocomplete: "off", placeholder: 'Contraseña' %>
</div>
<% if devise_mapping.rememberable? -%>
<div class="m-t"><%= f.check_box :remember_me %> <%= f.label :remember_me, '¿Recordar?' %></div>
<% end -%>
<div><%= f.submit "LOG IN", class: 'custom-input-2' %></div>
<% end %>
I'm trying to make the alert show a custom message instead of the INVALID EMAIL OR PASSWORD default one.
Is there a documentation about this somewhere or can someone explain to me how this is done.
I have an application that I have been working on and have everything wired up to my liking but was wondering if this is possible:
I am displaying a users username in an edit.html.erb template. I want it to display the users username inside of the <%= f.text_field :username, :class=> "uneditable-input" %>. I am using Bootstrap and in the documentation, it states to add a class of uneditable-input, when I hove rover the username text field, it shows a little white stop sign but I am still able to click on the field and edit it. Any help?
<%= render 'shared_partials/errors', errors_object: #user %>
<div class="page-header">
<h2> Edit Your Profile<small> - <%= #user.username %></h2></small>
</div>
<div class="well">
<%= form_for #user do |f| %>
<%= f.label :username %>
<%= f.text_field :username, :class=> "uneditable-input" %>
<%= f.label :password %>
<%= f.password_field :password, :class=> "input", :placeholder=>"Password goes here" %><br/>
<%= f.submit "Update Changes", class: 'btn btn-primary' %>
<% end %>
</div>
Make the field disabled.
<%= f.text_field :username, :class=> "uneditable-input", :disabled => true %>
While submitting the form, browser will not send the value for the field username and thats correct, why it should be sent if it is un-editable.