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

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…

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!

Select option not preselected after validation using collection in formtastic field

I'm 90% sure I'm doing something obviously wrong here, but when I'm using a select with a collection:
<%= f.input :description,
:label => "Which best describes who you are?",
:prompt => "Select an option...",
:collection => [[ "I am working for a company", "working"],["I am a freelancer", "freelancer"],["I am studying", "studying"],["I have recently graduated", "graduated"],["I teach", "teach"],["None of these things","none"]]
%>
and the form fails validation, the previously selected value is not selected, even though it is saved and is being passed to the params[:user][:description] as expected. Any ideas where I'm going wrong?
It's described there https://github.com/justinfrench/formtastic/wiki/Deprecation-of-%3Aselected-option#what-to-do-instead, so following should work
f.select :description,
options_for_select([[ "I am working for a company", "working"],["I am a freelancer", "freelancer"],["I am studying", "studying"],["I have recently graduated", "graduated"],["I teach", "teach"],["None of these things","none"]], f.object.description)
:label => "Which best describes who you are?",
:prompt => "Select an option...",
Also I would suggest moving collection to a separate helper method

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.

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

HashWithIndifferentAccess in related models

I've got a rails app where I'm linking fields across two databases. The database stuff all seems to be fine.
However, I have one form where I am mapping a description from the remote database to a product in the local database.
The form the used to create the product and select the description works fine
#_form.rb
semantic_form_for #products do |f|
f.input :name
semantic_fields_for :description_maps do |description|
description.input :desciption_map_id, :input_html=>{:name=>"product[description_map][description_id]}, :collection => #descriptions
end
end
#product.rb
class Product < ActiveRecord::Base
attr_accessible :name, :description_map_attributes, :description_map
has_one :description_map
accepts_nested_attributes_for :description_map
when I submit the form, I get an error
DescriptionMap(#...) expected, got ActiveSupport::HashWithIndifferentAccess(#othernumber)
I can't seem to figure out why this is happening.
the parameters being posted look fine
"product"=>{"name"=>"test name",
"description_map"=>{"description_id"=>"1"}}
turns out this was an issue with how formtastic was naming the description map.
In the question, i had specified
description.input :desciption_map_id, :input_html=>{:name=>"product[description_map][description_id]}, :collection => #descriptions
but the 'description_map' needed to be 'description_map_attributes' like this
description.input :desciption_map_id, :input_html=>{:name=>"product[description_map_attributes][description_id]}, :collection => #descriptions
Hopefully this answer helps somebody else having the same issue.
You should use: :description_map (without "S") cause is a has_on relation
semantic_fields_for :description_map do |description|
description.input :desciption_map_id, :input_html=>{:name=>"product[description_map] [description_id]}, :collection => #descriptions
end

Resources