2009-09-06 77 views
1

當我使用Rails腳手架時,我無法訪問該頁面來編輯字段。它向我展示了所有DATE字段的一些問題。這裏的錯誤:DATE字段的Rails腳手架問題

can't convert Symbol into String 

Extracted source (around line #124): 

    121: </p> 
    122: <p> 
    123:  <%= f.label :dataDeCadastro %><br /> 
    124:  <%= f.date_select :dataDeCadastro %> 

和部分堆棧跟蹤的:

/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_view/helpers/date_helper.rb:564:in `include?' 
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_view/helpers/date_helper.rb:564:in `select_date' 
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_view/helpers/date_helper.rb:832:in `to_date_select_tag_without_error_wrapping' 
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_view/helpers/active_record_helper.rb:268:in `to_date_select_tag' 
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_view/helpers/date_helper.rb:179:in `date_select' 
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_view/helpers/date_helper.rb:889:in `date_select' 
app/views/usuarios/edit.html.erb:124 
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_view/helpers/form_helper.rb:313:in `fields_for' 
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_view/helpers/form_helper.rb:253:in `form_for' 
app/views/usuarios/edit.html.erb:3 

和模型SQL:

CREATE TABLE `usuarios` (
    `id` int(11) NOT NULL AUTO_INCREMENT, 
    `usuario` varchar(50) DEFAULT NULL, 
    `recebeNews` smallint(1) DEFAULT NULL, 
    `cidade` varchar(30) DEFAULT NULL, 
    `email` varchar(40) DEFAULT NULL, 
    `endereco` varchar(70) DEFAULT NULL, 
    `estado` varchar(3) DEFAULT NULL, 
    `cep` varchar(10) DEFAULT NULL, 
    `numero` varchar(10) DEFAULT NULL, 
    `telefone` varchar(30) DEFAULT NULL, 
    `cnpj` varchar(20) DEFAULT NULL, 
    `cpf` varchar(18) DEFAULT NULL, 
    `inscricaoEstadual` varchar(20) DEFAULT NULL, 
    `rg` varchar(15) DEFAULT NULL, 
    `complemento` varchar(70) DEFAULT NULL, 
    `sexo` varchar(1) DEFAULT NULL, 
    `bairro` varchar(70) DEFAULT NULL, 
    `telefoneResidencial` varchar(10) DEFAULT NULL, 
    `dddTelefoneCelular` varchar(2) DEFAULT NULL, 
    `dddTelefoneComercial` varchar(2) DEFAULT NULL, 
    `dddTelefoneResidencial` varchar(2) DEFAULT NULL, 
    `ramalDoTelefoneComercial` varchar(10) DEFAULT NULL, 
    `telefoneCelular` varchar(10) DEFAULT NULL, 
    `telefoneComercial` varchar(10) DEFAULT NULL, 
    `creditoPessoal` smallint(1) DEFAULT NULL, 
    `descontoPessoal` smallint(1) DEFAULT NULL, 
    `motivoDoBloqueio` varchar(255) DEFAULT NULL, 
    `nomeNaReceitaFederal` varchar(255) DEFAULT NULL, 
    `valorDoCreditoPessoal` double DEFAULT NULL, 
    `valorDoDescontoPessoal` double DEFAULT NULL, 
    `bloqueio` smallint(1) DEFAULT NULL, 
    `dataDeCadastro` datetime DEFAULT NULL, 
    `dataLimiteDoDescontoPessoal` datetime DEFAULT NULL, 
    `situacaoNaReceitaFederal` varchar(255) DEFAULT NULL, 
    `dataDeNascimento` datetime DEFAULT NULL, 
    `senha` varchar(255) DEFAULT NULL, 
    `interior` smallint(1) DEFAULT NULL, 
    `observacao` varchar(255) DEFAULT NULL, 
    PRIMARY KEY (`id`), 
    UNIQUE KEY `email` (`email`) 
) ENGINE=InnoDB AUTO_INCREMENT=5754 DEFAULT CHARSET=latin1 ; 

衆目睽睽來源:

<% form_for(@usuario) do |f| %> 
<%= f.error_messages %> 

<p> 
    <%= f.label :usuario %> 
    <%= f.text_field :usuario %> 
</p> 
<p> 
    <%= f.label :cpf, "CPF" %> 
    <%= f.text_field :cpf %> 
</p> 
<p> 
    <%= f.label :rg, "RG" %> 
    <%= f.text_field :rg %> 
</p> 
<p> 
    <%= f.label :cnpj, "CNPJ" %> 
    <%= f.text_field :cnpj %> 
</p> 
<p> 
    <%= f.label :sexo, "Sexo" %><br> 
    <%= f.radio_button :sexo, :M %>M<br> 
    <%= f.radio_button :sexo, :F %>F 
</p> 
<p> 
    <%= f.label :dataDeNascimento, "Data de Nascimento" %> 

    <%= f.date_select :dataDeNascimento %> 
</p> 
<p> 
    <%= f.label :endereco %> 
    <%= f.text_field :endereco %> 
</p> 
<p> 
    <%= f.label :cidade, "Cidade" %> 
    <%= f.text_field :cidade %> 
</p> 
<p> 
    <%= f.label :estado, "Estado" %> 
    <%= f.text_field :estado, :maxlength => "2" %> 
</p> 
<p> 
    <%= f.label :cep, "CEP" %> 
    <%= f.text_field :cep, :maxlength => "10" %> (00000-000) 
</p> 
<p> 
    <%= f.label :telefone, "Telefone" %> 
    <%= f.text_field :telefone %> 
</p> 
<p> 
    <%= f.label :email %> 
    <%= f.text_field :email %> 
</p> 
<p> 
    <%= f.label :senha, "Senha" %> 
    <%= f.password_field :senha %> 
</p> 
<p> 
    <%= f.label :senha_confirmation, "Confirmação da Senha" %> 
    <%= f.password_field :senha_confirmation %> 
</p> 
<p> 
    <%= f.label :recebeNews %><br /> 
    <%= f.check_box :recebeNews %> 
</p> 
<p> 
    <%= f.submit "Enviar" %> 
</p> 
<% end %> 

拿什麼是?

回答

11

我已經找到了解決方案上this linkone

When in your application you have set the I18n.locale to something different than "en" and you have the following simple code in your view:

<%= date_select("user_info", "birthdate") %> 

You'll get the can't convert Symbol into String for the date_select helper. The problem can be rescued by giving the date_select helper order like this:

<%= date_select("user_info", "birthdate", :order => [:day,:month,:year]) %> 

or by doing order in the yml file usually located at config/locales/your_lang.yml like this

date: 
    formats: 
    default: "" 
    long: "" 
    short: "" 
    order: 
    - :year 
    - :month 
    - :day 
+0

這清楚地解決了這個錯誤,雖然其他問題,如月翻譯失蹤後提高。我建議任何人有這個問題從https://github.com/svenfuchs/rails-i18n/tree/master/rails/locale – chech 2012-05-25 16:19:43

0

你能否也顯示錯誤信息?

UPDATE:

<p> 
    <%= f.label :dataDeNascimento, "Data de Nascimento" %> 

    <%= f.date_select "dataDeNascimento" %> 
</p> 

或試試這個:

<p> 
    <%= f.label :dataDeNascimento, "Data de Nascimento" %> 

    <%= date_select "usario", "dataDeNascimento" %> 
</p> 
+0

你能告訴我你的模型嗎? – Lichtamberg 2009-09-08 09:16:00

+0

請給我看你的完整表單代碼。在你的問題文本中看到你的sql語句是格式化代碼會很好。 – Lichtamberg 2009-09-09 11:05:35

+0

現在有問題的所有細節 – 2009-09-09 17:11:51

3

這是極有可能通過定位所致。您輸入的標準語言環境不同於:en(在application.rb或environment.rb中),但是您尚未爲月份名稱聲明合適的翻譯,導致導軌無法使用。您可以從GitHub下載標準翻譯文件。

+0

複製整個日期樹同樣的錯誤如上 - 這是我的原因。 – 2011-01-31 08:36:42