Avd*_*ept 4 ruby ruby-on-rails
我一直在关注M. Hartl 的Ruby-on-Rails教程中的练习.我已经完成了第4章中的所有练习,但我仍然坚持这一点:
创建三个哈希名称
person1
,person2
和person3
,以及键:first
和下的名字和姓氏:last
.然后创建一个params
哈希,即params[:father]
isperson1
,params[:mother]
isperson2
和params[:child]
isperson3
.例如,验证是否params[:father][:first]
具有正确的值.
任何人都可以建议如何处理这个问题?在我解决这个问题之前,我不想继续下一章.
Uni*_*key 19
person1 = {:first => 'Al', :last => 'Bundy'}
person2 = {:first => 'Peggy', :last => 'Bundy'}
person3 = {:first => 'Kelly', :last => 'Bundy'}
params = {
:father => person1,
:mother => person2,
:child => person3
}
params[:father][:first] #=> 'Al'
Run Code Online (Sandbox Code Playgroud)
这是建立params Hash的另一种方法.我发现从javascript背景中感觉更熟悉:
person1 = {first: "Papa", last: "Bear"}
person2 = {first: "Mama", last: "Bear"}
person3 = {first: "Baby", last: "Bear"}
params = {father: person1, mother: person2, child: person3}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
929 次 |
最近记录: |