Ruby on Rails, formtastic gives different HTML - ruby-on-rails

I have this template:
- f.inputs do
= user.input :is_vip?, :as => :boolean, :label=>'VIP'
= f.input :test, :as => :boolean, :required => false, :label => "This is TEST company"
= f.input :multi_destination, :as => :boolean, :required => false, :label => "Multi destination"
It's fully working thing. But the code that the browser receive is different in my localhost and in stage server. I don't know where to dig.
CSSes are exactly the same, sources are same, everything is the same.

Formtastic, by default, uses a method named label_with_nested_checkbox for rendering boolean input fields. That method renders the checkbox inside the label - like you are getting in localhost.
Formtastic doesn't have any "default way" to "take the input field out of the label" (his author confirmed this to me on this question) It must have been patched somehow to do that. Here're some possible places to look:
Check inside the apps/inputs directory, if there is any. That's the "standard" place where someone can modify Formtastic plugins
Check the config/initializers directory. To see if there is any Formtastic monkeypatching there.
Check the vendors directory.
Finally, even if the gem versions are the same, some could (grasp!) have changed the code of the gem itself in the server. I certainly hope they nave not. But anyway, uninstalling and reinstalling the gem, and maybe rebooting the server, should check that one out.

Related

activeadmin adding datepicker

I'm working with rails' activeadmin and creating a custom form like so:
<%= semantic_form_for [:admin, Client.find(#wedding_cake.client_id), #wedding_cake] do |f| %>
than I want to add an input for a date like so:
<%= f.input :date, as: :datepicker %>
However, I'm getting "Unable to find input class for datepicker" from rails.
I've tried including jquery date picker in my gem file, but that didn't change anything. What am I doing wrong?
I ran into this exact issue and what worked for me was: https://github.com/activeadmin/activeadmin/wiki/Combine-datetime-picker-with-activeadmin#or-do-it-manually
Specifically:
In active_admin, change the column use
:as => datepicker TO :as => :string, :input_html => {:class => "hasDatetimePicker"}
However, I had to prepend the datepicker class, and in my case, change hasDatetimePicker to hasDatePicker
:as => :string, :input_html => {:class => 'datepicker hasDatePicker'}
h/t to Eugen's comment for pointing me in the right direction
Try the DateNTimePickerActiveAdmin Rubygem. It works really well and is customisable according to your project.
You can find the documentation here: https://github.com/NikhithaGraceJosh/date_n_time_picker_activeadmin
From the docs:
Gemfile
gem 'date_n_time_picker_activeadmin'
Code Sample (In your form)
f.input :column_name, as: :datetimepicker
CSS
In active_admin.scss, add the line,
#import date_n_time_picker_activeadmin
JS
In active_admin.js, add the line,
//= require date_n_time_picker_activeadmin
Hope it's useful!

Autosize-rails not working

I am trying to use the autosize-rails gem to create text boxes that automatically get bigger when filled. I installed the gem and bundled it.
gem 'autosize-rails
I then added this to my js.coffeescript file:
$(document).ready ->
$("textarea").autosize()
and finally my form looks like this:
<%= f.input :title, as: :text, input_html: { :class => "textarea" }%>
The forms still use the default scroll bar.
I have no experience with this gem, but it looks like you need to change $("textarea") to $(".textarea") in your coffeescript file.

Ruby on Rails Formtastic Checkbox Not Checking (Collection.map)

I am working on a rails (& gems) project migration, and i am having some problems due to formtastic checkboxs which aren't being checked ( :collection => ... .map { ... } ).
The scenario happens when editing an object, it is supposed to print all possible profiles, translating them to the current user locale, and check which are associated with my current user.
The following code is working for Formtastic 1.2.4 and there was no model/controller/view code or database modified. Supposedly it would work for 2.2.1, but it happens that doesn't work for any 2.x version. Rails v.3.1.12
Views/_form.html.haml
= f.input :groups, :as => :check_boxes, :hint => i18n_hint_str("user_roles"), :collection => #current_organization.groups.joins(:permissions).permission_on("idea","index").map{ |u| [i18n_user_str("role.#{u.name}"),u.id] }
The select boxs below are just an output test, which surprisingly works in both versions, but what i truly want are the checkboxs.
Formtastic 1.2.4
Image Link : i.stack.imgur.com/7aruc.png
Formtastic 2.2.1
Image Link : i.stack.imgur.com/Af7LK.png
If i remove the .map part
= f.input :groups, :as => :check_boxes, :hint => i18n_hint_str("user_roles"), :collection => #current_organization.groups.joins(:permissions).permission_on("idea","index")
It will check the associated profiles, but without the translation part (Formtastic 2.2.1)
Image Link : i.stack.imgur.com/M0Xd7.png
Any ideas to make this working on Formtastic 2.2.1? I don't want to use javascript in this.
Thanks.

Ruby on Rails looking for value from key in devise gem

I'm new to ruby on rails, and I installed devise on my application. I was wondering where I can customize the values if a value is given in views/devise/registrations/new.html.erb
for example:
<%= f.input :password_confirmation, :required => true %>
this gives out an input and a label, the label is * Password confirmation. How do I customize this label and the input field?
Thanks
<%= f.input :password_confirmation, :required => true, :label => 'something', :class => 'something' %>
Define the something class in CSS and you'll be fine.
And of course, generate the partials via copying from devise directly or using its generators. I usually copy them from devise repo since I am not that much fan of generators, sometimes they generate files I don't even need or want.
rails generate devise:views users
You will need to generate the partials first. After that you can use those generated files to override the default ones. Also, it might be good to build the authentication from scratch the first time in order to better understand the process.
http://railscasts.com/episodes/250-authentication-from-scratch

Formtastic non-model form, integration with external site, override/specify the input ID values

I'm using formtastic to collect information from a form and post dirctly to an external site.
I have no problem generating the form itself. However, since this is being submitted to an external site, they require that each input field have the specific IDs they specify, eg email or last_name -- not the closest Formtastic form, eg _email_input or _last_name_input.
I've looked at the Formtastic v1.2.3 code and I'm 90% sure the answer is "sorry, can't do that." I figured it couldn't hurt to check if I'm missing something. I would like some way to specify the ID completely, as in:
= semantic_form_for('', :url => "https://external_site.com/handler, :method => "post") do |form|
= form.input :last_name, :id => "last_name"
[etc]
Is this possible?
(I will note that I recognize that another, arguably superior approach would be to create an appropriate controller, sanity check the parameters locally, and dispatch the remote call from within the app only when it's well formed; however, that's not what I'm trying to do at the moment.)
Firstly i think you need to use semantic_fields_for for non-model forms. Next, to pass ids to each field, you can use the input_html options to specify them. for eg
form.input :email, :input_html => {:name => 'email', :id => 'email' }

Resources