Checkboxes in formtastic bootstrap - ruby-on-rails

Recently, I installed the formtastic-bootstrap gem on my ruby-on-rails application. I have the following code on one of my forms that includes check-boxes:
<% if #gallery.tag_list.empty? %>
<%= f.input :tag_list, :as => :check_boxes, :label => _('Select Applicable Tags'), :collection => Gallery::DEFAULT_TAGS.sort, :wrapper_html => {:class => 'horizontal_list'} %>
<% else %>
<%= f.input :tag_list, :as => :check_boxes, :label => _('Current Tags'), :collection => #gallery.tag_list.sort, :wrapper_html => {:class => 'horizontal_list'} %>
<% end -%>
Even though formtastic-bootstrap is rendering the rest of my form correctly, my checkboxes are not showing up. The text next to the check-boxes appears, but the checkboxed themselves do not. Any suggestions to get this working are welcome. I have been trying to circumvent this little, annoying issue all day.

I had to create a bootstrapcustom.css.scss to over-ride the bootstrap properties of padding and margins on check-box elements in order to make them appear in the end.

Related

Selected drop down menu in simple_form when f.association is present in the view

Can you please tell me if there is a way using simple_form with Rails, when you have "f.associations" present in a view, to disable the selected drop down menu in the form but still use the prefilled value of the field?
I have tried with option ":disabled => true" but it disables the whole text field and a I need a value to be present here. When I submit the form I receive an error that a value should be present.
I have tried with option ":as => :hidden", the input value does not appear, but when I submit the form I receive an error that a value should be present.
I have tried with option ":readonly => true", but drop down menu still appears. It appears grayed out but can still be selected.
Thank you,
Silviu
Use input hidden with same variable and value for f.assocation disabled, when submit form, the needing value will be sended at once time.
Sample code illustrate the case, note line f.association :company get the value company_id but not send, so the f.input :company_id will replace, and works!
Welcome to project railstrace !
<p>Simple Form content: </p>
<%= simple_form_for #user, url: save_path, :method => :post do |f| %>
<%= f.input :email %>
<%= f.association :company, disabled: true %>
<%= f.input :company_id, :as => :hidden, :input_html => {:value => #user.company_id} %>
<%= f.association :roles %>
<%= f.button :submit %>
<% end %>

Simple form format a time field to show '21:30' instead of entire UTC time string

My rails _form code:
<%= simple_form_for #admin_event, :html => { :class => 'main-form' } do |f| %>
<%= f.input :time_of_event, :format => l(:time_of_event, '%d %b. %Y'), :as => :string, :label => 'Hora', :input_html => { :class => 'thin', :placeholder => 'eg: 20:30' } %>
<% end %>
I'm getting the error message:
Cannot convert symbol to string.
How can I set up this _form to always display this field using a time converter so while the database has a full field (2000-01-01 19:30:00.000000), in the forms it would only show 19:30?
Solved this with the following: created the method "time_format" on my ApplicationHelper:
def time_format(datetime)
datetime.strftime('%H:%M') unless datetime.blank?
end
And then on the form:
<%= f.input_field :start_time, :as => :string, :value => time_format(f.object.start_time) %>
Hope this will help you.
You can add attr_accessor to your model (for example formatted_time) and use this field for get fromatted time and set it. Before save you can parse value of #formatted_time and apply it to time_of_event field.

Restricting length of a form using simple_form?

I'm using simple form for a basic login form for my site within the nav area at the top of the page.
Currently, it's spilling the form fields over two rows and no matter how many display: inline attributes I apply. It still refuses to go back onto one line.
What im trying to do is restrict the number of characters in the form so that the fields fit onto one line.
Here's my current form code..
<%= simple_form_for("user", :url => user_session_path, :html => {:id => "sign_in", :class => 'form-inline' }, :remote => true, :format => :json) do |f| %>
<%= f.input :email %>
<%= f.input :password %>
<%= f.submit 'Login' %>
<%= link_to "Forgot your password?", new_password_path('user') %>
<% end %>
Easy way is to simply use the maxlength html attribute for inputs:
f.input :name, :input_html => { :maxlength => x }
But that will just restrict the number of characters that can be added into a single input. If your problem is with the width of those inputs, just use CSS to specify a custom width per input so the inputs won't overflow into a second line.

Rails simple_form association help with option tag

In my form I have:
<%= f.association :virksomhed, :collection => Virksomhed.all(:order => 'navn'), :prompt => "Vælg virksomhed" %>
In view I have this:
I instead of the object I want to display the name (navn on danish) of the companyies.
I believe you're looking for the :label_method option:
<%= f.association :virksomhed, :collection => Virksomhed.all(:order => 'navn'), :prompt => "Vælg virksomhed", :label_method=>:navn %>

Can't upload photo using paper clip in RoR

I use this code to upload photos, I find that it is not successfully upload photo, but other content can be updated.
<% semantic_remote_form_for(#product, :html => {:multipart => true}) do |f| %>
<% f.inputs do %>
<%= f.input :title, :label => "Name" %>
<%= f.input :category , :include_blank => false , :label => "Category" %>
<%= f.input :price, :label => "Price" %>
<%= f.input :photo, :label => "Photo" %>
<% end %>
<%= f.buttons %>
<% end %>
The code from server log:
DEPRECATION WARNING: Disabling
sessions for a single controller has
been deprecated. Sessions are now lazy
loaded. So if you don't access them,
consider them off. You can still
modify the session cookie options with
request.session_options.. (called from
/onlineStore/app/controllers/application_controller.rb:6)
Processing ProductsController#update
(for ::1 at 2010-01-23 22:03:54) [PUT]
Parameters: {"commit"=>"Save Product",
"authenticity_token"=>"vOvxOPYYE1wRGDYTEH5ciHrNJXUpGTJku3etIpCmf1c=",
"id"=>"33",
"product"=>{"price"=>"874",
"title"=>"Other products",
"category_id"=>"142"}, "_"=>""}
I'm surprised it worked at all, since Javascript is not supposed to be able to upload files via AJAX. Was the new switch the fact that you made it a remote form for the product? Since even though it's a gem helping with the semantic form building, even it shouldn't be able to do file uploads in that fashion.

Resources