Rails 脚手架中 DATE 字段的问题
当我使用Railsscaffold时,无法访问页面编辑字段。它向我展示了所有日期字段的某种问题。这是错误:
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 %>
以及 stackTrace 的一部分:
/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 %>
它可能是什么?
When I use Rails scaffold, I can't access the page to edit fields. It shows me some kind of problem with all DATE fields. Here's the error:
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 %>
And part of the stackTrace:
/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
And the model 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 ;
full view source:
<% 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 %>
What could it be?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我在此链接上找到了解决方案还有这个一个:
I've found the solution on this link and this one:
这很可能是本地化造成的。您输入了与 :en 不同的标准语言环境(在 application.rb 或environment.rb 中),但您尚未声明月份名称的适当翻译,导致rails 犹豫不决。您可以从 GitHub 下载标准翻译文件。
This is highly likely to be caused by localization. You have entered a different standard locale than :en (in application.rb or environment.rb), but you have not declared the appropriate translations for month names, causing rails to balk. You can download standard translation files from GitHub.
您还可以显示错误消息吗?
更新:
或尝试以下操作:
Could you show also the error-message?
UPDATE:
or try this: