I use gem twitter-bootstrap-rails in my ruby on rails project.
But the css class "icon-white" doesn't work.
I can see definiton of "icon-white" in gem toolkit.But in chrome dev tools,I can't find it.
Why?
How to solve?
<h2>Sign in</h2>
<%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
<div><%= f.label :email %><br />
<%= f.email_field :email %></div>
<div><%= f.label :password %><br />
<div class = "icon-user icon-white"></div>
<%= f.password_field :password %></div>
<% if devise_mapping.rememberable? -%>
<div><%= f.check_box :remember_me %> <%= f.label :remember_me %></div>
<% end -%>
<div><%= f.submit "Sign in" %></div>
<% end %>
<%= render "devise/shared/links" %>
Bootstrap Icons are meant for the <i> element.
<i class="icon-user icon-white"></i>
They will not work on a <div>
http://twitter.github.com/bootstrap/base-css.html#icons
(Scroll down to "How to use")
Related
This may be somewhat of a simple question but if i add a column called name to the devise User model and then add :name to attr_accessible in the User model, can i allow a user to login without specifying their name,
so sign up form looks like this
<h2>Sign up</h2>
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<p><%= f.label :name %><br />
<%= f.text_field :name %></p>
<p><%= f.label :email %><br />
<%= f.email_field :email %></p>
<p><%= f.label :password %><br />
<%= f.password_field :password %></p>
<p><%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation %></p>
<p><%= f.submit "Sign up" %></p>
<% end %>
<%= render :partial => "devise/shared/links" %>
and the sign in form will look like this
<h2>Sign in</h2>
<%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
<div><%= f.label :email %><br />
<%= f.email_field :email %></div>
<div><%= f.label :password %><br />
<%= f.password_field :password %></div>
<% if devise_mapping.rememberable? -%>
<div><%= f.check_box :remember_me %> <%= f.label :remember_me %></div>
<% end -%>
<div><%= f.submit "Sign in" %></div>
<% end %>
<%= render "devise/shared/links" %>
I just want to be able to collect their name upon sign up so i can use it later on in the app, but its not needed for login credentials?
Users signing in using email and password by default. You can add so much fields as you want in the registration form. It's will not affect on the sign in behavior.
i've a problem with password confirmation validation
in User Model:
validates :password, :confirmation => true
and in the view new.html.erb:
<%= form_for(#user) do |f| %>
<div class="field">
<%= f.label :password %><br />
<%= f.password_field :password %><br />
<%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation %><br />
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
so for any inserted data the validation throw error.
i think that there's something wrong with :password_confirmation and RoR received it with nil value
is it possibile? how can i do?
try this
class User < ActiveRecord::Base
validates :password, :presence =>true, :confirmation =>true
validates_confirmation_of :password
end
The Controller is intended take the data from the view and try to perform save, this is the code of the view:
<%= form_for(#user) do |f|%>
<% if #user.errors.any? %>
....
....
<% end %>
<%= f.label :email %><br />
<%= f.text_field :email %><br />
<%= f.label :password %><br />
<%= f.password_field :password %><br />
<%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation %>
<%= f.submit %>
<% end %>
NOTE: This check is performed only if password_confirmation is not nil, and by default only on save.
To require confirmation, make sure to add a presence check for the confirmation attribute:
http://ar.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html
I have the following two _forms:
user form
<%= simple_form_for(#user, :url => #target) do |f| %>
<% if #user.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#user.errors.count, "error") %> prohibited this user from being saved:</h2>
<ul>
<% #user.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<%= f.input :email, :label => "User Email" %>
<%= f.input :password, :label => "User Password" %>
<%= f.input :first_name %>
<%= f.input :last_name %>
<%= f.button :submit %>
<% end %>
tenant form
<%= simple_form_for(#tenant, :url => #target) do |f| %>
<% if #tenant.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#tenant.errors.count, "error") %> prohibited this tenant from being saved:</h2>
<ul>
<% #tenant.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<%= f.input :name, :label => 'Name', :required => true %>
<%= f.input :billing_email, :label => 'Email', :required => true %>
<%= f.input :country, :label => 'Country', :required => true %>
<%= f.button :submit %>
<% end %>
I have come across the following post from stackoverflow f.error_messages in Rails 3.0
Here there is method so that error messages can be returned from the simple form by using f.error_messages but I have been unable to get this working as I am unsure whereabout this method should be saved. Anyone got any hints? The method is as follows:
class StandardBuilder < ActionView::Helpers::FormBuilder
def error_messages
return unless object.respond_to?(:errors) && object.errors.any?
errors_list = ""
errors_list << #template.content_tag(:span, "There are errors!", :class => "title-error")
errors_list << object.errors.full_messages.map { |message| #template.content_tag(:li, message) }.join("\n")
#template.content_tag(:ul, errors_list.html_safe, :class => "error-recap round-border")
end
end
Just add error: false to your inputs this will not clear the css but will clear the inline errors
f.input error: false
Edit:
From http://ruby.railstutorial.org/book/ruby-on-rails-tutorial
/app/views/shared/_error_messages.html.erb
<% if object.errors.any? %>
<div id="error_explanation">
<div class="alert alert-error">
The form contains <%= pluralize(object.errors.count, "error") %>.
</div>
<ul>
<% object.errors.full_messages.each do |msg| %>
<li>* <%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
in VIEW
<%= form_for(#user) do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<%= f.label :name %>
<%= f.text_field :name %>
<%= f.label :email %>
<%= f.text_field :email %>
<%= f.label :password %>
<%= f.password_field :password %>
<%= f.label :password_confirmation, "Confirmation" %>
<%= f.password_field :password_confirmation %>
<%= f.submit "Create my account", class: "btn btn-large btn-primary" %>
<% end %>
I load my custom view with this config in devise.rb
config.scoped_views = true
and then this is my app/views/users/sessions/new.html.erb
<div class="container">
<div id="login">
<%= devise_error_messages! %>
<%= simple_form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
<div class="login">
<li><%= f.label :email %> <%= f.text_field :email %></li>
<li><%= f.label :password %> <%= f.password_field :password %></li>
</div><!-- login -->
<div class="reset">
<%= f.input :email, :required => false, :autofocus => true %>
<%= f.input :password, :required => false %>
<%= f.input :remember_me, :as => :boolean if devise_mapping.rememberable? %>
</div>
<div class="login">
<%= f.button :submit, "Sign in" %>
</div>
<% end %>
<%= render "links" %>
</div><!-- login -->
</div><!-- container -->
When I submit it just goes back to the page.
When I disable scoped.views it logs in fine.
I forgot you uncomment this line
config.default_scope = :user
Hi
Im working with a form and have added :remote => true to the form and the destroy link. But when I do that this happends:
I submit the form and it makes 2 versions that are the same.
I destroy, I get prompted twice?
If i remove the :remote => true it only makes one version and only prompt once.
This is my form
<%= form_for([#comment], :remote => true) do |f| %>
<% if #comment.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#comment.errors.count, "error") %> prohibited this comment from being saved:</h2>
<ul>
<% #comment.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :title %>
<br/>
<%= f.text_field :title %>
</div>
<div class="field">
<%= f.label :body %>
<br/>
<%= f.text_area :body %>
</div>
<div class="field">
<%= f.hidden_field :user_id %>
<%= f.hidden_field :retailer_id %>
<%= f.hidden_field :product_id %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
This is my destroy link
<%= link_to 'Destroy', comment, :confirm => 'Are you sure?', :method => :delete, :remote => true %>
Am I doing something very wrong here? Thanks in advance!
I think you have included your rails.js file twice. that might be the problem. check it.