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

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.

Related

formtastic with spree check_boxes using collection not saving checked items in edit form

I am using formtastic-2.2.1, Spree 1.3 and Rails 3.2.18.
This in my form input that I am having issues with:
= f.input :collection_products, :as => :check_boxes, :label => false, :collection => Spree::Product.order("name").all
The issue I am having is when I create a new collection_page and hit edit previously selected items are unselected in the edit form, all the other inputs are working as expected.
I've tried it with a simple collection, like :collection => ["x", "y", "z"]
ie:. If I select "x", "y" and try to edit it, they are no longer selected.
Collection Page model:
class CollectionPage < ActiveRecord::Base
has_many :spree_products, :class_name => Spree::Product
and added belongs_to :spree_collection_pagesto product_decorator.rb
I'm having the exact same issue as formtastic check_boxes using collection not saving checked items in edit form
Would be awesome if someone can help out!
Thanks a lot.
I ended up solving it by using simple_form instead and did the following on my form:
= f.association :spree_products, :collection => Spree::Product.order("name").all, :prompt => "Choose products for this collection"

Rails formtastic is asking for a country plug-in.. I don't want it. Anyone know how to tell it I don't want it?

I'm using formtastic and I've got a field country.. I'm getting this error when I attempt to display the screen.
To use the :country input, please install a country_select plugin,
like this one: https://github.com/jamesds/country-select
Now. I don't want to use any plugin.. It's free text, and I want to keep it that way.
Anyone know how to remove this requirement? Should be easy as... but I'm buggered if I can see how.
= semantic_form_for #store, {:html => { :class => "form-horizontal" }} do |f|
= f.input :default_country
Add
, :as => :string
to the end of the line that's causing the error
= semantic_form_for #store, {:html => { :class => "form-horizontal" }} do |f|
= f.input :default_country, :as => :string
In Rails 4, formtastic with country select input field:
Add 'country-select' to your Gemfile:
gem 'country-select'
If I use semantic form select, it doesn't shows previously saved value. So, the following is not working properly:
=f.input :country, as: :select, collection: country_options_for_select
So have to use standard form elements to get working:
=f.select :country, collection: country_options_for_select
I found that this plugin works out of the box (note the underscore instead of the dash):
https://github.com/chrislerum/country_select

Date::DAYNAMES doesn't offer a proper :select :collection on Windows

When I try to create a dropdown from Date::DAYNAMES on my Mac and my work Windows 7 machine, I get a select box with an index and the day name. However, when I move it to my Netbook (Windows 7), all I get is the first letter of the day name despite having the same exact code. Any ideas how to fix it?
Selected ActiveAdmin registration code:
ActiveAdmin.register Assessment do
form do |f|
f.inputs do
f.input :start_dow, :as => :select,
:collection => Date::DAYNAMES.each_with_index
end
f.buttons
end
end
I don't know why it worked sometimes in the past, but I switched it to:
f.input :start_dow, as => :select,
:collection => Date::DAYNAMES.each_with_index.to_a
Now it seems to work just fine on all the platforms I've used for testing so far. Perhaps it was different versions of ruby that were the issue? I've recently found that I've been using different versions…

Ruby on Rails, formtastic gives different HTML

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.

ActiveAdmin, Formtastic, and Paperclip: Not Rendering File Dialog

I'm implementing a generic media gallery using Ruby on Rails. I've chosen ActiveAdmin to handle the administration portion of my task and it's worked well so far, except for one thing: It's not displaying the "Choose file" dialog as intended.
This is a form for my "Media" section of ActiveAdmin. I have a model called "Medium" with the following fields (in addition to id and timestamp:
asset_file_name
asset_file_size
asset_content_type
asset_updated_at
My Medium model looks like this:
class Medium < ActiveRecord::Base
has_and_belongs_to_many :galleries
has_and_belongs_to_many :entities
has_attached_file :asset, :styles => { :medium => "300x300>", :thumb => "100x100>" }
attr_accessible :asset
end
And I'm adding it to the ActiveAdmin form like this:
form :html => { :enctype => "multipart/form-data" } do |f|
f.input :asset, :as => :file
f.buttons
end
Here's a screencap of my ActiveAdmin page:
I see nothing wrong with how I'm implementing this. I've read that Formtastic has historically had issues with paperclip and I'm not averse to switching to attachment_fu or any other suitable solutions.
I should also note: I know that I can add in a custom partial. It's not my ideal solution, as I'd like to keep everything in the Formtastic DSL.
Thanks!
Formtastic requires that you wrap all calls to #input in a call to #inputs. It's definitely something that I would like to see fixed in Active Admin.
It should work if you wrap your input in a call to inputs:
form :html => { :enctype => "multipart/form-data" } do |f|
f.inputs do
f.input :asset, :as => :file
end
f.buttons
end
Let me know if this works for you.
Or you can do:
form :html => {:multipart => true} do |f|
which is easier to remember, imho.
the latest active admin handle it automatic
I use carrier wave with active admin and works as above.

Resources