我一直在关注 Ruby-on-Rails tutorial 中的练习由 M. Hartl 着。我已经完成了第 4 章中的所有练习,但仍停留在这一章上:
Create three hashes called
person1
,person2
, andperson3
, with first and last names under the keys:first
and:last
. Then create aparams
hash so thatparams[:father]
isperson1
,params[:mother]
isperson2
, andparams[:child]
isperson3
. Verify that, for example,params[:father][:first]
has the right value.
谁能建议如何解决这个问题?在我解决这个问题之前,我不想继续下一章。
最佳答案
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'
关于ruby-on-rails - M. Hartl 的 RoR 书中的练习,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10723061/