Devise login form with form_inline in the navbar - ruby-on-rails

I am trying to make a Devise login form as form_inline in my navbar.
At this point a have made it like this:
Link to picture of the navbar it look like a this point: http://postimg.org/image/i3ka5fsur/
it has the code:
<li><%= form_for(:user, :url => session_path(:user)) do |f| %>
<%= f.text_field :email, :placeholder => "Email" %>
<%= f.password_field :password, :placeholder => "Password" %>
<%= f.check_box :remember_me %><%= f.label :remember_me %>
<%= f.submit 'Login' %>
<% end %></li>
I'm just not quite happy with it's look at this point, I more want it like the form_inline:
Link to picture of the navbar I want it to look like: http://postimg.org/image/7590n949f/
the form_inline code is:
<form class="form-inline">
<input type="text" class="input-small" placeholder="Email">
<input type="password" class="input-small" placeholder="Password">
<label class="checkbox">
<input type="checkbox"> Remember me
</label>
<button type="submit" class="btn">Sign in</button>
</form>
Hope some of you can help me, i'm new a programmering and don't have a lot of experience with programmering.

with twitter bootstrap3
<%= form_for(:user, :url => session_path(:user), html: { class: "navbar-form navbar-right form-inline" }) do |f| %>
<div class="form-group">
<%= f.text_field :email, :placeholder => "Email", class: "form-control" %>
</div>
<div class="form-group">
<%= f.password_field :password, :placeholder => "Password", class: "form-control" %>
</div>
<div class="checkbox">
<%= f.check_box :remember_me %><%= f.label :remember_me %>
</div>
<%= f.submit 'Login', class: "btn btn-default" %>
<% end %>
with twitter bootstrap2
<%= form_for(:user, :url => session_path(:user), html: { class: "navbar-form pull-right form-inline" }) do |f| %>
<%= f.text_field :email, :placeholder => "Email", class: "input-small" %>
<%= f.password_field :password, :placeholder => "Password", class: "input-small" %>
<label class="checkbox">
<%= f.check_box :remember_me %><%= f.label :remember_me %>
</label>
<%= f.submit 'Login', class: "btn" %>
<% end %>

You should include the css that describes form_inline class and input-small class e.t.c
Then in your code you should assign classes to your elements like below
<li><%= form_for(:user, :url => session_path(:user)), :class => "form-inline" do |f| %>
<%= f.text_field :email, :placeholder => "Email", :class => "input-small" %>
<%= f.password_field :password, :placeholder => "Password", :class => "input-small" %>
<%= f.check_box :remember_me, :class => "checkbox" %><%= f.label :remember_me, :class => "checkbox" %>
<%= f.submit 'Login', :class => "btn" %>
<% end %></li>

Related

How can i add an FontSwesome icon in the same line?

I use my rails with devise (login system). That works. Now I will add in FA-Icon to as my label.
This is my target:
But this my current state (the hook is my test icon):
That is my code:
<div class="container">
<%= form_for(resource, as: resource_name, url: session_path(resource_name), html: {class: "form-signin"}) do |f| %>
<h2 class="form-signin-heading">Please sign in</h2>
<%#= f.label :email, 'Email Address', class: 'sr-only' %>
<i class="fa-solid fa-check"></i>
<%= f.email_field :email, autofocus: true, class: 'form-control', placeholder: 'Email Address' %>
<%= f.label :password, 'Password', class: 'sr-only' %>
<%= f.password_field :password, autocomplete: "off", class: 'form-control', placeholder: 'Password' %>
<% if devise_mapping.rememberable? -%>
<div class="checkbox">
<label><%= f.check_box :remember_me %> Remember me</label>
</div>
<% end %>
<%= f.button "Sign in", class: 'btn btn-lg btn-primary btn-block' %>
<% end %>
<%= render "devise/shared/links" %>
</div>
Can someone give me a hint, what i am doing wrong?

Devise login always returns "Invalid Email or Password", even when they're right

I know it's apparently a frequent question (saw many replies here), but I couldn't fix it yet.
So.. I'm building a simple blog app with devise gem, but when I try to log in, I always get the "Invalid Email or password." message :/
Actually, this is my first real project with rails, so sometimes I'm kinda lost with routes, and etc... By the way, I would say the error is probably being caused by the routes file.
Please, I'd appreciate some help :)
My routes.rb file:
Rails.application.routes.draw do
root 'posts#index'
resources :posts do
resources :comments
end
devise_for :users
devise_scope :user do
get "login", :to => "devise/sessions#new"
get "logout", :to => "devise/sessions#destroy"
end
My sessions/new.html.erb file:
<div class="container mt-3 pb-3">
<div class="row">
<div class="col-lg-6 border">
<h1>Login</h1>
<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
<div class="form-group">
<%= label_tag :email, "Email" %>
<%= text_field_tag :email, "", autofocus: true, :class =>"form-control" %>
</div>
<div class="form-group">
<%= label_tag :password, "Senha" %>
<%= password_field_tag :password, "", :class =>"form-control" %>
</div>
<div class="form-group">
<%= submit_tag "Entrar", :class =>"form-control btn btn-outline-dark" %>
</div>
<% end %>
<%= render "devise/shared/links" %>
</div>
</div>
</div>
My registrations/_form.html.erb:
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= render "devise/shared/error_messages", resource: resource %>
<div class="form-group">
<%= f.label :username, "Nome" %>
<%= f.text_field :username, autofocus: true, autocomplete: "username", :class =>"form-control" %>
</div>
<div class="form-group">
<%= f.label :email, "Email" %>
<%= f.email_field :email, autocomplete: "email", :class =>"form-control" %>
</div>
<div class="form-group">
<%= f.label :password, "Senha" %>
<% if #minimum_password_length %>
<em>(No mínimo <%= #minimum_password_length %> caracteres)</em>
<% end %><br />
<%= f.password_field :password, autocomplete: "new-password", :class =>"form-control" %>
</div>
<div class="form-group">
<%= f.label :password_confirmation, "Confirme sua senha" %><br />
<%= f.password_field :password_confirmation, autocomplete: "new-password", :class =>"form-control" %>
</div>
<div class="form-group">
<%= f.submit "Criar", :class =>"form-control btn btn-outline-dark" %>
</div>
<% end %>
JUST ANOTHER THING! MAYBE IT'S IMPORTANT...
I have a navbar rendered in "layouts/application.html.erb" that shows the current user's name and a logout button when there's a user connected, and a login button when there are no sessions.
<% unless current_page? (login_path) %>
<%= link_to 'Entrar', login_path, :class =>"btn btn-outline-light" %>
<% end %>
Your error was caused by wrong sign_in form.
I have changed this part
<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
<div class="form-group">
<%= label_tag :email, "Email" %>
<%= text_field_tag :email, "", autofocus: true, :class =>"form-control" %>
</div>
<div class="form-group">
<%= label_tag :password, "Senha" %>
<%= password_field_tag :password, "", :class =>"form-control" %>
</div>
<div class="form-group">
<%= submit_tag "Entrar", :class =>"form-control btn btn-outline-dark" %>
</div>
<% end %>
To this one, and everything worked.
<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
<div class="form-group">
<%= f.label :email, "Email" %>
<%= f.text_field :email, autofocus: true, :class =>"form-control" %>
</div>
<div class="form-group">
<%= f.label :password, "Senha" %>
<%= f.password_field :password, :class =>"form-control" %>
</div>
<div class="form-group">
<%= f.submit "Entrar", :class =>"form-control btn btn-outline-dark" %>
</div>
<% end %>

Rails 5 & Devise: Login always returns incorrect password

Fresh install of Devise, I'm able to register a new user. But after logging out, I can't login and devise returns "Invalid Email or password."
When I look at User.last I see the correct email. User.last.password is nil and User.last.encrypted_password returns an encrypted password.
Routes:
resources :users
devise_for :users, path: '', path_names: { sign_up: 'register', sign_in: 'login', sign_out: 'logout'}
registrations/new:
<%= form_for(resource, as: resource_name, url: user_registration_path, :html => {:class => "col s12 form-text"}) do |f| %>
<div class="row">
<div class="input-field col s12">
<%= f.text_field :full_name, :class => "validate", :placeholder => "Robin Smith" %>
<%= f.label :full_name, :class => "allcaps" %>
</div>
</div>
<div class="row">
<div class="input-field col s12">
<%= f.email_field :email, :class => "validate" %>
<%= f.label :email, :class => "allcaps" %>
</div>
</div>
<div class="row">
<div class="input-field col s12">
<%= f.password_field :password, :class => "validate" %>
<%= f.label :password, :class => "allcaps" %>
</div>
</div>
<div class="button-container">
<%= f.submit :class => "waves-effect waves-light btn-flat", :value => "Join Now" %>
</div>
<% end %>
sessions/new:
<%= form_for :session, :html => {:class => "col s12 form-text"} do |f| %>
<div class="row">
<div class="input-field col s12">
<%= f.email_field :email, :class => "validate" %>
<%= f.label :email, :class => "allcaps" %>
</div>
</div>
<div class="row">
<div class="input-field col s12">
<%= f.password_field :password, :class => "validate" %>
<%= f.label :password, :class => "allcaps" %>
</div>
</div>
<div class="button-container">
<%= f.submit :class => "waves-effect waves-light btn-flat", :value => "Login" %>
</div>
<% end %>
Where am I going wrong?
Looks like you modified the default sessions/new view that Devise generates.
This is the default:
<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
so make sure :session is doing what it's supposed to.

adding html id to form_tag rails 4

I currently have this sign in form in a rails 4 app in which I use the form_tag helper. I'm need to add an id. I tried using <%= form_tag( :html => {:id => 'login_form'} ) do %> but I get an error.
<%= form_tag do %>
<div class="form-group">
<%= label_tag :name, 'Username:', class: "control-label" %>
<div class="controls">
<%= text_field_tag :name, params[:name], class: "form-control", size: "30", tabindex: "1" %>
</div>
</div>
<div class="form-group">
<%= label_tag :password, 'Password:' %>
<div class="controls">
<%= password_field_tag :password, params[:password], class: "form-control", size: "30", tabindex: "2" %>
</div>
</div>
<div class="form-group">
<div class="controls">
<%= submit_tag "Sign in", class:"btn btn-large", tabindex: "2" %>
</div>
</div>
<% end %>
<%= form_tag('/login', id: "login-form") do %>

How to hide a form field and still have it submit all the fields?

I've got this rails form partial:
<%= form_for #ptab, :remote => true, :html => { :class => 'form-horizontal' } do |f| %>
<div class="control-group">
<%= f.label :name, :class => 'control-label' %>
<div class="controls">
<%= f.text_field :name, :class => 'text_field', :placeholder => 'Enter a name...' %>
</div>
</div>
<div class="control-group">
<%= f.label :address, :class => 'control-label' %>
<div class="controls">
<%= f.text_field :address, :class => 'text_field', :placeholder => 'Paste a link...' %>
</div>
</div>
<div class="control-group">
<%= f.label :sequence, :class => 'control-label' %>
<div class="controls">
<%= f.number_field :sequence, :class => 'number_field', :placeholder => 'Enter an order number...' %>
</div>
</div>
<div class="control-group">
<%= f.label :gtab_id, :class => 'control-label' %>
<div class="controls">
<%= f.number_field :gtab_id, :class => 'number_field' %>
</div>
</div>
<div class="modal-footer">
<%= f.submit nil, :class => 'btn btn-primary' %>
<!-- <%= link_to t('.cancel', :default => t("helpers.links.cancel")), ptabs_path, :class => 'btn' %> --> <!-- this was the original cancel button -->
<a data-dismiss="modal" class="btn" href="#">Close</a>
</div>
<% end %>
I would like to turn the field in the last .control-group into a hidden field, but I still want it to be submitted to the controller.
What should I change this to :
<div class="control-group">
<%= f.label :gtab_id, :class => 'control-label' %>
<div class="controls">
<%= f.number_field :gtab_id, :class => 'number_field' %>
</div>
</div>
In order for it to not show in the rendered form but still be submitted with the form?
Use a hidden_field ? Or did I miss something ?
<%= f.hidden_field :gtab_id %>
And of course remove the divs around it as well as the label. hidden_field are submitted as regular fields, no worries

Resources