Rails unable to change label in formtastic - ruby-on-rails

Hi I'm new to rails and formtastic.
I've built a working solution for multiple file uploads using paperclip.
In my form, when I try and change the label of the upload file it still displays 'image' even when changing to:
<%= f.inputs :image, :label => false, :for => :attachments, :as => :file %>
or
<%= f.inputs :image, :label => "This label will not display", :for => :attachments, :as => :file %>
really silly problem but any help would be appreciated
thanks

f.inputs does not support label attribute, you should use f.input if you want hide label. Or you can bypass this and hide label via css. Something like this.
label[for=here_go_your_for_value] {
display: none;
}

Related

make simple form radio buttons hidden

How can I get a hidden radio button using simple-form?
I know that simple-form has a :as => :hidden to hide a form field, and a :as => :radio_buttons to display a radio button option... but I can't have two as options on a field... :)
How can I go about this?
What I've tried:
= form.input :type,
:as => :radio_buttons,
:hidden => true,
:checked => ...
= form.input :type,
:as => [:radio_buttons, :hidden]
:checked => ...
= form.input :type,
:as => :radio_buttons,
:as => :hidden,
:checked => ...
"hidden" is a different form of input altogether - it's the same as hidden_field. If you just want to hide a radio from the user (maybe you want to show it again later) you can use "display: none" in the html for the wrapper.
= form.input :type
as: radio_buttons
wrapper_html: { style: "display: none" }
If the input should never be displayed to the user then I'd just leave it out of the page altogether. You're never going to be able to selected it after all.

Rails ActiveAdmin with carrierwave

I am using ActiveAdmin with rails 4 and it is working fine. When I add an item, I am taken to the index page listing the new item/items and the filters on the right side. Also, there are the email and logout links at the top right.
My issue is when I add an item with an image the filters, email and logout links disappear.
If I delete the item with the image they appear again. I can add /new to the url and it still takes me to the form but I am trying to figure out why adding a picture removes the links.
here is my form:
form(:html => { :multipart => true }) do |f|
f.inputs "Size" do
f.input :title
f.input :description
f.input :price
f.input :image, :as => :file
f.input :developer_days
f.input :designer_days
f.input :name
end
f.actions
end
I just can't figure out why this happens.

How to insert hint information right after the input box?

Not really an issue but some question that I need
Is it possible to attached html values right after the input box? Something like a small text info below the input box
I have did something similar but its not pretty.
f.inputs "Blog" do
f.input :view_counts, :input_html => { :readonly => true }
f.input :slug
li raw("<label class='label'> </label><span class='text-info'>Your Slug will be automatically based on your title or you can choose to enter your own slug title</span>")
f.input :title
f.input :content, :as => :ckeditor
f.input :is_active
f.input :admin_user_id, as: :hidden, :input_html => { :value => current_admin_user.id }
end
The code is between :slug and :title. You will catch a draft of what I am trying to do. Thanks
you can add a label like:
<label for="slug" class="hint">Your Slug will be automatically based on your title or you can choose to enter your own slug title</label>
Then add css styling something like:
.hint {
font-weight: normal;
color: #777;
font-size: .85em;
}
Thanks for the help, I found the way to do it.
f.input :slug, hint:"love u"
This will add a small cursive text just below the input box.

Checkboxes in formtastic bootstrap

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.

Rails file_field does not upload anything

I am using Rails 4 and Ruby 2 with Carrier Wave along with jQuery Mobile 1.3, and a user has a profile which has a logo. I have tested the backend Carrier Wave stuff in the console and it works.
The problem is in the form helper, it doesn't matter what I do, but a file_field will display and let me choose an image, but it does not come through in the params. If I change it to a field that does not exist eg. =f.file_field :field_not_permitted_in_strong_params it does not fall over and a file picker is visible, if I change that to =f.text_field :field_not_permitted_in_strong_params, only then does rails kick in and complain about the field not existing.
So my problem is basically, I can upload a file client side, but it does not get sent through in the form data, or appear in the params hash, and all my other fields work correctly.
Here is a snippet of the form:
= form_for(#business_profile, :html => {:multipart => true}, :url => business_profile_path, :validate => true) do |f|
=image_tag(#business_profile.logo.url, class: 'business-logo')
%div{:data => {:role => 'fieldcontain'}}
=f.file_field :logo
- # Basic Information
%div{:data => {:role => 'collapsible', :collapsed => 'false'}}
%h3
Basic Information
%div{:data => {:role => 'fieldcontain'}}
= f.label :name, 'Business name:'
= f.text_field :name
%div{:data => {:role => 'fieldcontain'}}
= f.label :address, 'Address:'
= f.text_area :address, class: 'address'
OK after spending hours on the matter, the problem is that jQuery Mobile submits forms with Ajax by default, and files cannnot be submitted with Ajax without using plugins etc.
So the solution is to disable the Ajax like this:
= form_for(#business_profile, :url => business_profile_path, :validate => true, :html => { :'data-ajax' => false }) do |f|

Resources