开发者

problem with datetime field in Rails model

开发者 https://www.devze.com 2023-02-09 08:26 出处:网络
I have a problem with datetime attribute in Rails model. model: attr_accessor :from, :to, :via, :datetime

I have a problem with datetime attribute in Rails model.

model:

attr_accessor :from, :to, :via, :datetime

erb template:

<%= f.text_field :from %>
<%= f.text_field :to %>
<%= f.text_field :via %>
<%= f.datetime_select :datetime, :discard_year 开发者_开发知识库=> true %>

I got:

@datetime(4i)' is not allowed as an instance variable name

On this line: @search_form = SearchForm.new params[:search_form]

What's wrong?


I don't know exactly what's causing the error, but I can tell you that to fix it, you'll need to change the attribute name datetime to, say sent_on (most anything else, really).

Why the error? I'd guess it's because datetime is a data type in SQL, and thus shouldn't be used as a column name, but the error seems to be coming from ruby - either your model or ActionView, so I'm not sure if that supports my theory...

Anyway, hope this helps!

Update: I just tested it, and you can use "datetime" as a column name in SQL (MySQL, at least). There goes that theory - it's a Rails thing, then, I guess...

0

精彩评论

暂无评论...
验证码 换一张
取 消