我知道还有其他问题是相同的,但它们没有解决我的问题.
我不断收到错误: Aws::Errors::MissingRegionError in BooksController#create,
missing region; use :region option or export region name to ENV['AWS_REGION'].但是,这是我的配置
Development.rb:
config.paperclip_defaults = {
storage: :s3,
s3_host_name: "s3-us-west-2.amazonaws.com",
s3_credentials: {
bucket: ENV['AWS_BUCKET'],
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
s3_region: ENV['us-west-2']
}
}
Run Code Online (Sandbox Code Playgroud)
Production.rb:
config.paperclip_defaults = {
storage: :s3,
s3_host_name: "s3-us-west-2.amazonaws.com",
s3_credentials: {
bucket: ENV['AWS_BUCKET'],
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
s3_region: ENV['us-west-2']
}
}
Run Code Online (Sandbox Code Playgroud)
和Application.rb:
config.paperclip_defaults = {
storage: :s3,
s3_host_name: "s3-us-west-2.amazonaws.com",
s3_credentials: {
bucket: ENV['AWS_BUCKET'],
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
s3_region: ENV['us-west-2']
}
}
Run Code Online (Sandbox Code Playgroud)
但是,它不断出现错误.我从其他问题中听取了其他人的建议.希望有人能提供帮助.
本
我对ruby很新,所以忍受我,我有两个数组,我们打算找到丢失的数字.
起始数组序列为[1,2,3,4,5,6,7,8,9]具有一个删除数的混合数组为5 [3,2,4,6,7,8,1,9]
我的想法是将每个数组相加,看看哪个数字丢失了 - 我开始制作一个方法(我知道它很破旧,但我正在学习)
def find_deleted_number(arr, mixed)
arr = [1,2,3,4,5,6,7,8,9]
mixed = [3,2,4,6,7,8,1,9]
y = arr.inject(0){|sum,x| sum + x }
x = mixed_arr.inject(0){|total, y| total + y}
return y - x
end
Run Code Online (Sandbox Code Playgroud)
任何人都可以指导我在这里做错了吗?
要使用索引返回子字符串,我们可以这样做
string = "hello"
string[0] returns "h"
string[1] returns "e"
(and so on...)
Run Code Online (Sandbox Code Playgroud)
假设我有一个数组[1,2,3,4]和一个字符串"awesome".如何从数组中返回相关的子字符串?
[1,2,3,4] should return "weso"
Run Code Online (Sandbox Code Playgroud)
这是因为我有一个方法,它意味着在每个"r"之后返回子字符串并且它失败了:
您可以看到我找到了每个子字符串"r"的索引,并将其作为数组返回.下面的行将数组中的每个值递增+1.
我现在需要通过数组中的相关索引从字符串返回子串.
def pirates_say_arrrrrrrrr(string)
all_index = (0 ... string.length).find_all {|i| string[i] == "r"}
y = all_index.map do |i| i + 1
end
string[y.first..y.last]
end
# pirates_say_arrrrrrrrr("are you really learning Ruby?") # => "eenu"
# pirates_say_arrrrrrrrr("Katy Perry is on the radio!") # => "rya"
Run Code Online (Sandbox Code Playgroud) 我有一个方法返回找出哪个给定数字在均匀度上与其他数字不同并返回它的索引(+1).
def iq_test(numbers)
new_array = numbers.split(" ").collect {|n| n.to_i}
x = new_array.select(&:even?)
y = new_array.select(&:odd?)
if x.count > y.count
new_array.split.each_with_index do |value, index|
"#{index + 1}".to_i if value % 3 != 0
else y.count > x.count
"#{index + 1}".to_i if value % 2 == 0
end
end
end
Run Code Online (Sandbox Code Playgroud)
例如iq_test("2 4 7 8 10")应该返回3.
但是,我收到了
语法错误,意外的keyword_else,期待keyword_end
我无法找到我没有关闭一些代码的地方.
对于每个单词,我试图将单词的第一个字母移动到单词的末尾.例如,
"this is an example"----> "hist si na xamplee".例如,我用一个词实现了这个目标,
x = "hello"
x << x.split("").shift # => "elloh"
Run Code Online (Sandbox Code Playgroud)