This project is archived and is in readonly mode.
Error with date_select when a default_locale is set
Reported by Vincent Isambart | November 17th, 2008 @ 06:17 AM | in 3.x
After adding
I18n.default_locale = 'ja-JP'
in my environment.rb, I got the following error:
can't convert Symbol into String
when using
<%= f.date_select :contract_from %>
in my view.
The trace is:
/usr/lib/ruby/gems/1.8/gems/actionpack-2.2.1/lib/action_view/helpers/date_helper.rb:564:in `include?'
/usr/lib/ruby/gems/1.8/gems/actionpack-2.2.1/lib/action_view/helpers/date_helper.rb:564:in `select_date'
/usr/lib/ruby/gems/1.8/gems/actionpack-2.2.1/lib/action_view/helpers/date_helper.rb:832:in `to_date_select_tag_without_error_wrapping'
/usr/lib/ruby/gems/1.8/gems/actionpack-2.2.1/lib/action_view/helpers/active_record_helper.rb:268:in `to_date_select_tag'
/usr/lib/ruby/gems/1.8/gems/actionpack-2.2.1/lib/action_view/helpers/date_helper.rb:179:in `date_select'
/usr/lib/ruby/gems/1.8/gems/actionpack-2.2.1/lib/action_view/helpers/date_helper.rb:889:in `date_select'
If I install the localized_date plugin, I get a proper error in the console, but the "can't convert Symbol into String" of standard Rails does not mean anything for the normal user.
Comments and changes to this ticket
-
Vincent Isambart November 22nd, 2008 @ 03:39 AM
I investigated a little more and there is at least one problem with ActionView::Helpers::DateTimeSelector#translated_date_order. The current code is
def translated_date_order begin I18n.translate(:'date.order', :locale => @options[:locale]) || [] end end
However, I18n.translate never returns nil/false. If it did not find anything, it will return a "translation missing: xxxx" string. And later calling .include(:symbol) on it will throw an exception. At first I thought about adding :default => [] in the translate()'s options, but the only defaults that can be used are strings (if you give an Array, it looks for the strings in it). To return an empty array if nothing was found you would have to do something like this:
def translated_date_order begin order = I18n.translate(:'date.order', :locale => @options[:locale]) if order.respond_to?(:to_ary) order else [] end end end
I tried it and date_select displayed "Some date". A nice error would be better but it's still better than a strange "can't convert Symbol into String" exception.
-
Josh Delsman November 25th, 2008 @ 06:19 PM
Yep, I am having the same problem. I have the default set to "en-US", and I get the same Can't convert Symbol to String error.
-
n3uro5i5 November 28th, 2008 @ 11:35 AM
I used your code, but i changed the empty array to a default date order.
module ActionView module Helpers
class DateTimeSelector def translated_date_order begin order = I18n.translate(:'date.order', :locale => @options[:locale]) if order.respond_to?(:to_ary) order else [:year, :month, :day] end end end end
end end
-
Dwayne Macgowan December 17th, 2008 @ 03:05 AM
I have the same problema.
While the problem is solved what you can do is explicit your :order every time you call date_select. This will avoid the error.
-
Mr.Devin December 17th, 2008 @ 01:25 PM
I had the same problem but found that since this is the datetime selector you need to add :time in your default order. this might be obvious to other but i am a bit dense so it is good to make not of this for other who are like me. :)
@@@RUBY class DateTimeSelector def translated_date_order
begin order = I18n.translate(:'date.order', :locale => @options[:locale]) if order.respond_to?(:to_ary) order else [:year, :month, :day, :time] end end
end end
-
Dwayne Macgowan December 17th, 2008 @ 01:58 PM
I found a better solution. You need to define your localization for time formats. You can get some pre-made localization files for many languages at: http://github.com/svenfuchs/rail...
-
Yaroslav Markin December 26th, 2008 @ 10:41 AM
@bruno :'en-US' is not the default locale anymore, did you try :en?
-
DavidBackeus January 21st, 2009 @ 04:39 PM
I solved it by adding a en-US.yml with the formats on this page: http://i18n-demo.phusion.nl/page.... Would be nice if the helpers would be fixed to use rails defaults if no specifics are found.
-
Ryan Bigg April 10th, 2010 @ 11:38 AM
- Assigned user set to Sven Fuchs
I have asked Sven Fuchs to take a look at this and give his opinion.
-
Sven Fuchs April 10th, 2010 @ 12:13 PM
- State changed from new to open
Thanks for reporting this.
I guess the implementation is just wrong. It should pass the :raise => true option (so I18n.t would raise a MissingTranslationException) and then rescue from the exception.
Also, it should help to add the locale fallbacks module here which is included in the I18n gem but it apparently is not obvious how to use it. Pratik mentioned that he wanted to enable it by default which should solve the problem with translation data missing for locales other than :en.
http://github.com/svenfuchs/i18n/blob/master/lib/i18n/backend/fallb...
-
Draiken October 8th, 2010 @ 03:16 PM
- Importance changed from to
Is this gonna get fixed or should I manually include the fallbacks on my projects?
-
rails March 14th, 2011 @ 12:00 AM
- Tag changed from 2.2, date, i18n to 22, date, i18n
This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.
Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.
-
rails March 14th, 2011 @ 12:00 AM
- State changed from open to stale
-
csnk May 18th, 2011 @ 08:28 AM
We are the professional underwear manufacturer, underwear supplier, underwear factory, custom underwear.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>