小编Dan*_*Dan的帖子

Rails 5弃用警告和向初始化程序添加代码?

我应该向哪个初始化文件添加所需的代码行?我收到以下弃用警告.

弃用警告:时间列将成为Rails 5.1中的时区感知.这仍然导致Strings被解析为好像它们在Time.zone,并且Times被转换为Time.zone.

要保留旧行为,您必须将以下内容添加到初始化程序:

config.active_record.time_zone_aware_types = [:datetime]
Run Code Online (Sandbox Code Playgroud)

要使此弃用警告静音,请添加以下内容:

config.active_record.time_zone_aware_types = [:datetime, :time]
Run Code Online (Sandbox Code Playgroud)

我是铁杆新手,我只想遵循最佳实践.谢谢!

ruby-on-rails

5
推荐指数
1
解决办法
2178
查看次数

在Ruby中删除字符串中的元音

我正在测试以下问题的可能解决方案.我提出的"开膛"和"开膛机_2"的前两个解决方案运行不正常.我想找出原因.

Disembowel_3是迄今为止我最喜欢的解决方案.但是如果我不明白我的前两个解决方案出了什么问题,我觉得我无权使用disembowel_3.

谁能帮我弄清楚前两个解决方案有什么问题?

# Write a function disemvowel(string), which takes in a string,
# and returns that string with all the vowels removed. Treat "y" as a
# consonant.

def disemvowel(string)
  string_array = string.split
  vowels = %w[aeiou]
  i = 0
  while i < string.length
    if vowels.include? string[i] == true
      string_array[i] =  " "
    end
    i +=1
  end

  new_string = string_array.join
  new_string = new_string.sub(/\s+/,"")
  return new_string
end


def disemvowel_2(string)
  string_array = string.split('')
  string_array.delete('a','e','i','o','u')
  return string_array.join('')
end

# This is my favorite …
Run Code Online (Sandbox Code Playgroud)

ruby string replace

3
推荐指数
1
解决办法
2980
查看次数

标签 统计

replace ×1

ruby ×1

ruby-on-rails ×1

string ×1