相关疑难解决方法(0)

Rails单行if else语句

我试图在视图中写一条if if语句.

<%= collection.name ? collection.name : @miniature.name %>
Run Code Online (Sandbox Code Playgroud)

如果存在,我希望它放入collection.name,否则我希望它放入@minile.name

ruby-on-rails ruby-on-rails-4

16
推荐指数
2
解决办法
3万
查看次数

如何在ruby中使用哈希值获取默认值

我想在ruby中使用哈希时尝试获取默认值.查找文档,您使用了一个fetch方法.因此,如果未输入哈希,则默认为值.这是我的代码.

def input_students
  puts "Please enter the names and hobbies of the students plus country of    birth"
  puts "To finish, just hit return three times"

  #create the empty array
  students = []
  hobbies = []
  country = []
  cohort = []

  # Get the first name
  name = gets.chomp
  hobbies = gets.chomp
  country = gets.chomp
  cohort = gets.chomp

  while !name.empty? && !hobbies.empty? && !country.empty? && cohort.fetch(:cohort, january) do #This is to do with entering twice
    students << {name: name, hobbies: …
Run Code Online (Sandbox Code Playgroud)

ruby

5
推荐指数
2
解决办法
7854
查看次数

标签 统计

ruby ×1

ruby-on-rails ×1

ruby-on-rails-4 ×1