ruby-on-rails - M. Hartl 的 RoR 书中的练习

标签 ruby-on-rails ruby

我一直在关注 Ruby-on-Rails tutorial 中的练习由 M. Hartl 着。我已经完成了第 4 章中的所有练习,但仍停留在这一章上:

Create three hashes called person1, person2, and person3, with first and last names under the keys :first and :last. Then create a params hash so that params[:father] is person1, params[:mother] is person2, and params[:child] is person3. 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/

相关文章:

ruby-on-rails - 我应该如何处理 ruby 中的这种关系?

MySQL 和 MySQL2 gem 在主机上构建,但不通过 Capistrano 或 SSH 构建

ruby-on-rails - Ruby:绑定(bind)在 ActiveRecord gem 中意味着什么?

ruby-on-rails - Ruby mod_passenger 进程超时

ruby-on-rails - 您如何为ActiveStorage URL解决N + 1?

html - GMail 中 <td> 的宽度无效

ruby - 打印我比。在 Ruby 中打印“#{i}?不将它添加到字符串中是否有区别?

ruby - 如何使用 bundler 重新安装 gem

ruby-on-rails - Gemfile 中同一 gem 的不同版本 - 可能吗?

ruby-on-rails - unicorn 不会关闭数据库连接