remember me not working simple form - ruby-on-rails

I am using Devise for authentication. Trying to edit/create devise forms with simple_form.
this
<%= simple_form_for(resource, :as => resource_name, :url => session_path(resource_name), :html=>{:class=>"form-vertical"}) do |f| %>
<%= f.input :email, :placeholder=>"Email", :label=>false %>
<%= f.input :password, :placeholder=>"Password", :label=>false %>
<% if devise_mapping.rememberable? -%>
<div style="display:inline"><%= f.input :remember_me, :inline_label => 'Yes, remember me'%></div>
<%end -%>
<div><%= f.submit "Sign in", :class=>"pull-right btn btn-primary" %></div>
<div><%= link_to "Create an account", new_user_registration_path%></div>
<% end %>
is literally giving me; Remember Me, which should be checkbox

Maybe use
<%= f.input :remember_me, :as => :boolean %>

Related

How do I add an autocomplete="street-address" attribute to rails form_for

I'm trying to add Mapbox autofill to my address bar on rails, for mapbox autofill to work I need to have autocomplete="street-address in an input field.
I'm using simple_form_form and I can't figure out how to add autocomplete attribute. Here is my form:
<%= simple_form_for #lock do |f| %>
<div class="form_wrapper">
<div class="form_div">
<%= f.input :name %>
<%= f.input :description %>
<mapbox-address-autofill>
<%= f.input :address, :autocomplete => "street-address" %>
</mapbox-address-autofill>
<%= f.input :photo, as: :file, label: "Link to picture" %>
<%= f.input :special_content %>
<%= f.button :submit, :class => "btn btn-primary" %>
<% end %>
any ideas on how to make the autocomplete attribute work?
Use input_html and pass the additional options like class etc.
<%= f.input :address, input_html: { :autocomplete => "street-address"} %>

Input field not showing up

On this edit page screen I've set up a "Current Password" field required to edit the user information (to change my name for example) but for some reason that particular current password field is not showing up while all the other input fields do.
I can't figure out why its not showing up?
Thank you!
<%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name), html: { :method => :put, class: 'form-horizontal'}) do |f| %>
<%= f.error_notification %>
<%= f.input :name, :label => "Nombre" %>
<%= f.input :email, :label => "Correo Electronico" %>
<%= f.input :password, :label => "Nueva Contraseña", autocomplete: "off" %>
**<%= f.input :password_confirmation, :label => 'Confirmar Contraseña', autocomplete: "off" %>**
<% f.input :current_password, :label => "Contraseña Actual" %>
</br>
<div class= "form-actions">
<%= f.submit "Actualizar Datos", class: "btn btn-primary"%>
</div>
<% end %>
You forgot to add the = in the ERB tab. It won't echo to the page without that. It should look like this:
<%= f.input :current_password, :label => "Contraseña Actual" %>
Keep in mind, statements whose values you do not want to show on the page should omit the equals (=) sign. Examples of those statements would be things like <% if ... %>, <% #some_var.each do .... %> etc.
Values you do wish to appear on the page, such as your input line, should have the equals sign.

using existing inputs to create form for user to sign in

using User model, created by devise, and Simple Form gem i want to give user ability to log in from main page. i have inputs, created just for it in haml, and want to use them for this:
.login-wrapper
.user-fields
%input{type: "text", placeholder: "username", class: "ribbon-placeholder mail"}
.slide
%input{type: "password", placeholder: "password", class: "ribbon-placeholder password"}
= link_to "#", class: "ribbon-button" do
%span register
.account-arrow
.clearfix
%input{type: "submit", value: "log in", class: "ribbon-button orange-background log-in"}
Ok you can use the form like this. This is just for reference is not exactly form like yours:-
<%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
<div><%= f.label :email %>
<%= f.email_field :email, :autofocus => true %></div>
<div><%= f.label :password %>
<%= f.password_field :password %></div>
<% if devise_mapping.rememberable? -%>
<div>
<label class="checkbox" for="merchant_remember_me">
<%= f.check_box :remember_me %> Remember Me
</label>
</div>
<% end -%>
<br />
<div><%= f.submit "Sign in" %></div>
<% end %>

simple_form problems with login

first off I'm very new to rails - I'm playing about with a little log in application had it all working and decided to try out simple form - however I can't get my log in form to work with the gem.
Here is what I had and had working;
<h2>Log In</h2>
<%= form_tag sessions_path do %>
<div class="field">
<%= label_tag :email %>
<%= text_field_tag :email, params[:email] %>
</div>
<div class="field">
<%= label_tag :password %>
<%= password_field_tag :password %>
</div>
<p><%= link_to "Forgotten Password?", new_password_reset_path %></p>
<div class="field">
<%= check_box_tag :remember_me, 1, params[:remember_me] %>
<%= label_tag :remember_me %>
</div>
<div class="actions"><%= submit_tag "Log In" %></div>
<% end %>
And here is what I tried to change it to using simple form.
<h2>Log In</h2>
<%= simple_form_for :sessions, :url => sessions_path, :html => { :class => 'form-vertical' } do |f| %>
<%= f.input :email, :required =>false, :label => 'Email Address',:placeholder => 'Email Address' %>
<%= f.input :password, :required =>false, :label => 'Password',:placeholder => 'Password' %>
<label class="checkbox">
<%= check_box_tag :remember_me, 1, params[:remember_me] %>
Remember me
</label>
<p>
<%= link_to "Forgotten Password?", new_password_reset_path %>
</p>
<%= f.button :submit "Login" %>
<% end %>
This seems to work okay until I try to log in - when I log in it is always displaying my invalid username and password message - I can't figure out where I'm going wrong here. Any help would be much appreciated!
Thanks!
In case 1, you are probably receiving params: { :email => '...', ....} and in case 2, :sessions => { :email => '...', ....}
Check params.inspect
Got it! Many thanks to Zabba for pointing me in the right direction;
My second method works;
<%= simple_form_for :sessions, :url => sessions_path, :html => { :class => 'form-vertical' } do |f| %>
<%= f.input :email, :required =>false, :label => 'Email Address',:placeholder => 'Email Address' %>
<%= f.input :password, :required =>false, :label => 'Password',:placeholder => 'Password' %>
<label class="checkbox">
<%= check_box_tag :remember_me, 1, params[:remember_me] %>
Remember me
</label>
<p>
<%= link_to "Forgotten Password?", new_password_reset_path %>
</p>
<%= f.button :submit "Login" %>
<% end %>
However I failed to update my controller so where I had;
def create
user = User.find_by_email(params[:email])
if user && user.authenticate(params[:password])
...
end
I had to update to;
def create
user = User.find_by_email(params[:sessions][:email])
if user && user.authenticate(params[:sessions][:password])
...
end
Thanks Zabba!

Client side validations with Devise

I am trying to use the client_side_validations gem with Devise to validate devise registrations form.
Validations work fine with everything else just not the Devise generated form.
I added the relevant :validate => true but the validations only work when I hit submit not on tab like they do on every other form.
<h2>Sign up</h2>
<hr />
<%= form_for(resource, :validate => true, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<div><%= f.label :username %>
<%= f.text_field :username %></div>
<div><%= f.label :email %>
<%= f.email_field :email %></div>
<div><%= f.label :password %>
<%= f.password_field :password %></div>
<div><%= f.label :password_confirmation %>
<%= f.password_field :password_confirmation %></div>
<br />
<div><%= f.submit "Sign up", :class => "btn btn-primary btn-large" %></div>
<% end %>
<%= render "links" %>
Argc, argv! I am using Rails 3.2.1, the latest release of the gem is incompatible with 3.2 hence the nightmare. Using 3.2.0.beta.2 fixes the problems. Thanks!
Try to put the :validates => true on your fields directly, like this :
<h2>Sign up</h2>
<hr />
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<div>
<%= f.label :username %>
<%= f.text_field :username, :validate => true %>
</div>
<div>
<%= f.label :email %>
<%= f.email_field :email, :validate => true %>
</div>
<div>
<%= f.label :password %>
<%= f.password_field :password, :validate => true %>
</div>
<div>
<%= f.label :password_confirmation %>
<%= f.password_field :password_confirmation, :validate => true %>
</div>
<br />
<div>
<%= f.submit "Sign up", :class => "btn btn-primary btn-large" %>
</div>
<% end %>
<%= render "links" %>
change the line
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
to
<%= form_for(#user, :url => registration_path(resource_name), :validate => true) do |f| %>
I haven't used client_side_validations gem extensively yet. But from the look of it, it needs to have data-validate="true" in the form (and form elements) tags.
Do you find it in the output html form like:
<form novalidate="novalidate" method="post" data-validate="true" action="/some_actions" >
If you don't find it, you might want to write your form_for like this:
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), {:validate => true}) do |f| %>
Does it help?
To use an stable version use 3.0.3 that was the latest stable version supporting rails 3.2.x

Resources