= simple_form_for #session, :as => 'session', :url => session_path do |form|
%form
.form-group
.form
= form.input :email
.form
= form.input :password
.form-actions
%button.btn.btn-primary{type: "submit"} Log in
above sample generates the following horizontal view, where input fields are to the right of labels
*Email [input]
*Password [input]
Is it possible to show them vertically on top of each other, so labels are above input fields? How can it be achieved?
*Email
[input]
*Password
[input]
= simple_form_for #session, :as => 'session', :url => session_path do |form|
%form
.form-group
.form
%div
= form.label :email
= form.email_field :email
%div
= form.label :password
= form.password_field :password
According to the github page:
https://github.com/plataformatec/simple_form
<%= f.input :username, label: 'Your username please' %>
Will make the label a block element, instead of inline_label.
Or you can specify the label and the input field seperately:
<%= f.label :username %>
<br/>
<%= f.input_field :username %>
Try this one:
%label Email*
%div
= form.input :email
%label Password*
%div
= form.input :password
Related
form_for :radio, url(:radio, :add), :method => :put do |f|
= f.error_messages
%p
= f.label :title, :caption => "Radio Name:"
= f.text_field :title
%p
= f.select :city_name, XXXXXXXXXXXXXX
%p
= f.label :frequency
= f.text_field :frequency
%p
= f.label :url
= f.text_field :url
%p
= f.submit "Add", :class => 'button'
When I put XXXXXXXX as
[['Hot','hot'],['Medium','medium'],['Cold','cold']]
or even
City.all.map {|c| [c.city]}
I get:
can't convert Array into Hash
Any help will be appreciated.
= f.select :city_name, City.all.map{ |c| [c.name, c.id] } try this
You just need to wrap the options in options_for_select. For example:
= f.select :city_name, options_for_select([['Hot','hot'],['Medium','medium'],['Cold','cold']])
data = %w/hot medium cold/.map { |s| [s.capitalize, s] }
= f.select :city_name, Hash[data]
Hash[data]
Please find below what solved for me
= f.select :city_name, :options => [["Delhi", "Delhi"], ["Mumbai", "Mumbai"], ["New York", "New York"], ["Punjab", "Punjab"]]
:options => was the key... But how come docs does not mention this. May be this is because of gem version difference.
Thanks everyone for help.
in my app I have form that looks like this
= simple_form_for #user do |f|
= f.input :name, error: false
= f.input :surname, error: false
Is there any way to avoid this repetitions (error: false)?
If they're all of the same type, something like this should work:
= simple_form_for #user do |f|
- [ :name , :surname ].each do |field|
= f.input field, error: false
If not, you could use a hash or something, instead of an array, and specify the type, as well.
It appears that simple form has the following option:
If you want to pass the same options to all inputs in the form (for
example, a default class), you can use the :defaults option in
simple_form_for. Specific options in input call will overwrite the
defaults:
<%= simple_form_for #user, defaults: { input_html: { class: 'default_class' } } do |f| %>
<%= f.input :username, input_html: { class: 'special' } %>
<%= f.input :password, input_html: { maxlength: 20 } %>
<%= f.input :remember_me, input_html: { value: '1' } %>
<%= f.button :submit %>
<% end %>
From https://github.com/plataformatec/simple_form
So, in your case:
= simple_form_for #user , defaults: { error: false } do |f|
= f.input :name
= f.input :surname
You could loop through an array of symbols
simple_form_for #user do |f|
[:name, :surname].each do |element|
f.input element, error: false
end
end
I use currency with ruby rails 4, I add fields in my user table I created with currency and the concern is when I want to change my email it works but if I want to update the other fields nothing happens so I do not know what 'would forget.
Here the form of currency or I add the fields.
%h2
Edit #{resource_name.to_s.humanize}
= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f|
= devise_error_messages!
%div
= f.label :email
%br
= f.email_field :email, :value =>"#{current_user.email}"
%div
= f.label 'Mot de passe'
%i (Pour valider votre profil)
%br
= f.password_field :current_password
%div
= f.label 'Nom'
%br
= f.text_field :username, :value=>"#{current_user.username}"
%div
= f.label 'Prenom'
%br
= f.text_field :firstname, :value=>"#{current_user.firstname}"
%div
= f.label 'Adresse'
%br
= f.text_field :adress, :value=>"#{current_user.adress}"
%div
= f.label 'Code postal'
%br
= f.text_field :cp, :value=>"#{current_user.cp}"
%div
= f.label 'Ville'
%br
= f.text_field :city, :value=>"#{current_user.city}"
%div= f.submit "Mise à jour du profil"
To update the custom fields that you added to Devise model, you will have to permit them explicitly:
Add the following code in your ApplicationController
class ApplicationController < ActionController::Base
before_filter :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
## Permit the custom fields below which you would like to update, I have shown a few examples
devise_parameter_sanitizer.for(:account_update) << :currency << :username << :firstname
end
end
I've got an app that uses Devise and the ClientSideValidations gems.
In the form below, I've got client side validations working with devise. I think it's working since the it's now impossible to actually submit the form. My problem is that none of the text, such as "can't be blank" will appear next to the text field tags. Any idea what I'm doing wrong?
%h3 Sign up
%br
= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :validate => true) do |f|
%h4
= devise_error_messages!
%div
= f.label :name
= f.text_field :name, :validate => true
%div
= f.label :email
= f.email_field :email, :validate => { :presence => :true }
%div
= f.label :password
= f.password_field :password, :validate => { :presence => :true, :length => true }
%div
= f.label :password_confirmation
= f.password_field :password_confirmation, :validate => { :presence => true }
%div
= f.submit "Sign up", id: 'button'
= render "devise/shared/links"
When I view source, the js appears.
<script>//<![CDATA[
if(window.ClientSideValidations==undefined)window.ClientSideValidations={};if(window.ClientSideValidations.forms==undefined)window.ClientSideValidations.forms={};window.ClientSideValidations.forms['new_user'] = {"type":"ActionView::Helpers::FormBuilder","input_tag":"<div class=\"field_with_errors\"><span id=\"input_tag\" /></div>","label_tag":"<div class=\"field_with_errors\"><label id=\"label_tag\" /></div>","validators":{"user[name]":{"presence":[{"message":"can't be blank"}]},"user[email]":{"presence":[{"message":"can't be blank"}]},"user[password]":{"presence":[{"message":"can't be blank"}],"length":[{"messages":{"minimum":"is too short (minimum is 6 characters)","maximum":"is too long (maximum is 128 characters)"},"allow_blank":true,"minimum":6,"maximum":128}]}}};
//]]></script>
So I know it there and I believe it's doing its job, but for some reason, I'm just not seeing the error messages I would expect when I leave a field blank.
When I copied _form.haml partial to _edit_form.haml partial and replaced "_form", with "_edit_form" in my edit.haml I got strange error (maybe it is not strange, I just cant understand the reason).
wrong number of arguments (0 for 1)
Extracted source (around line #1):
1: = form.label :email
2: %br
3: = form.text_field :email
4: %br
.../app/views/users/_edit_form.haml:1:in `form'
.../app/views/users/_edit_form.haml:1:in `_run_haml_app47views47users47_edit_form46haml_locals_edit_form_object'
.../app/views/users/edit.haml:5:in `_run_haml_app47views47users47edit46haml'
.../app/views/users/edit.haml:3:in `_run_haml_app47views47users47edit46haml'
Here is edit.haml:
%h1 Edit My Account
- form_for #user, :url => account_path do |f|
= f.error_messages
= render :partial => "edit_form", :object => f
= f.submit "Update"
%br
= link_to "My Profile", account_path
...and edit_form.haml
= form.label :email
%br
= form.text_field :email
%br
%br
= form.label :old_password, "Old password"
%br
= form.password_field :old_password
%br
%br
= form.label :password, "Change password"
%br
= form.password_field :password
%br
%br
= form.label :password_confirmation
%br
= form.password_field :password_confirmation
%br
I can't understand where is the problem. Because it worked nicely with _form.haml
diff _form.haml _edit_form.haml
1c1
< = form.label :login
---
> = form.label :email
3c3
< = form.text_field :login
---
> = form.text_field :email
6c6
< = form.label :email
---
> = form.label :old_password, "Old password"
8c8
< = form.text_field :email
---
> = form.password_field :old_password
11c11
< = form.label :password, form.object.new_record? ? nil : "Change password"
---
> = form.label :password, "Change password"
The :object is implicitly exposed in the partial as the name of the partial. Change form to edit_form in _edit_form.haml and it should work.