访问date()变量从rails的date helper发送 [英] Accessing date() variables send from the date helper in rails
问题描述
他的助手代码
<%= date_select(game,release_date order => [:day,:month,:year])%>
如何在控制器中访问返回的变量?
谢谢
date_select
helpper什么Rails调用多参数属性。也就是说, release_date
属性的值分割为由 date_select $ c创建的日,月,年的3个下拉列表$ c> helper。
date_select
按照惯例命名3个下拉菜单,以便在控制器中执行以下操作:
@game = Game.new(params [:game])
和<$新游戏中的c $ c> release_date 属性将填入选定的日期。
或
@ game.update_attributes(params [:game])
更新现有记录。
如果您检查参数或查看日志文件,您将看到3个单独的组件:
params [game] [release_date(1i)]#年
params [game] [release_date(2i )]#月份
params [game] [release_date(3i)]#一天
虽然您可以直接访问这些个别元素,但似乎并不是一个好主意。 date_select
helper真正被设计为与ActiveRecord的 attributes =
setter组合使用,在创建一个新对象或更新属性。
Hay, not sure if i've missed the point of the helpers in rails, but i used the date() helper and now i don't know how to access the variables returned.
Heres the helper code
<%=date_select("game", "release_date", :order => [:day, :month, :year])%>
How do i access the returned variables in a controller?
Thanks
The date_select
helper makes use of what Rails calls multi parameter attributes. That is, the value of the release_date
attribute is split across the 3 dropdowns for day, month, year which are created by the date_select
helper. date_select
names the 3 dropdowns following a convention such that in your controller you can do:
@game = Game.new(params[:game])
and the release_date
attribute on the new game will be populated with the date selected.
or
@game.update_attributes(params[:game])
to update an existing record.
If you inspect params or look in the log file you will see the 3 individual components:
params["game"]["release_date(1i)"] # the year
params["game"]["release_date(2i)"] # the month
params["game"]["release_date(3i)"] # the day
Whilst you could access these individual elements directly it doesn't seem like a good idea. The date_select
helper is really designed to be used in combination with the attributes=
setter of ActiveRecord which is used when creating a new object or updating attributes.
这篇关于访问date()变量从rails的date helper发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!