【发布时间】:2016-10-11 21:07:48
【问题描述】:
我正在尝试使用 Link Thumbnailer 从食谱网站获取标题、图像和描述,但由于某种原因,当我提供网站的 URL 时,我不断收到 BadUriFormat 错误。
在我看来,我有:
<% @recipes.each do |recipe| %>
<tr>
<td class="recipe-info">
<%= image_tag LinkThumbnailer.generate(recipe.image_link).images.first.src.to_s %>
</td>
</tr>
...这个例子中的配方是:
#<Recipe:0x007fe48394a358> {
:id => 1,
:name => "test",
:image_link => "http://paleoleap.com/simple-beef-shish-kabobs/"
}
这是我的错误:
ETHON: started MULTI
ETHON: performed EASY effective_url=http://res.cloudinary.com/paleoleap/image/upload/f_auto,q_90/v1459886762/j-paleo/simple-beef-shish-kabob-main.jpg response_code=200 return_code=write_error total_time=0.04831799999999997
ETHON: performed MULTI
ETHON: started MULTI
ETHON: performed EASY effective_url=http://paleoleap.com/pictures/icons/servings.png response_code=200 return_code=write_error total_time=0.053881
ETHON: performed MULTI
ETHON: started MULTI
ETHON: performed EASY effective_url=http://paleoleap.com/pictures/icons/prep3.png response_code=200 return_code=write_error total_time=0.050677
ETHON: performed MULTI
ETHON: started MULTI
ETHON: performed EASY effective_url=http://paleoleap.com/pictures/icons/cooking4.png response_code=200 return_code=write_error total_time=0.044727
ETHON: performed MULTI
ETHON: started MULTI
ETHON: performed EASY effective_url=http://res.cloudinary.com/paleoleap/image/upload/f_auto,q_90/v1459886762/j-paleo/simple-beef-shish-kabob-preparation.jpg response_code=200 return_code=write_error total_time=0.048975
ETHON: performed MULTI
Rendered recipes/index.html.erb within layouts/application (510.5ms)
Completed 500 Internal Server Error in 1040ms (ActiveRecord: 7.3ms)
LinkThumbnailer::BadUriFormat (LinkThumbnailer::BadUriFormat):
app/views/recipes/index.html.erb:46:in `block in _app_views_recipes_index_html_erb___148801017206438179_70110103402900'
app/views/recipes/index.html.erb:26:in `_app_views_recipes_index_html_erb___148801017206438179_70110103402900'
当我通过执行LinkThumbnailer.generate(Recipe.find(1)) 在控制器中获取图像时,它运行没有问题。
这里是成功的:
ETHON: started MULTI
ETHON: performed EASY effective_url=http://res.cloudinary.com/paleoleap/image/upload/f_auto,q_90/v1459886762/j-paleo/simple-beef-shish-kabob-main.jpg response_code=200 return_code=write_error total_time=0.056864
ETHON: performed MULTI
ETHON: started MULTI
ETHON: performed EASY effective_url=http://paleoleap.com/pictures/icons/servings.png response_code=200 return_code=write_error total_time=0.04847
ETHON: performed MULTI
ETHON: started MULTI
ETHON: performed EASY effective_url=http://paleoleap.com/pictures/icons/prep3.png response_code=200 return_code=write_error total_time=0.04541
ETHON: performed MULTI
ETHON: started MULTI
ETHON: performed EASY effective_url=http://paleoleap.com/pictures/icons/cooking4.png response_code=200 return_code=write_error total_time=0.039456
ETHON: performed MULTI
ETHON: started MULTI
ETHON: performed EASY effective_url=http://res.cloudinary.com/paleoleap/image/upload/f_auto,q_90/v1459886762/j-paleo/simple-beef-shish-kabob-preparation.jpg response_code=200 return_code=write_error total_time=0.0386
ETHON: performed MULTI
在我的循环中对recipe.image_link 调用generate 方法与在控制器中的特定Recipe 上调用它有什么区别?
【问题讨论】:
-
我看到你正在循环
@recipes的数组,你能显示那个数组的值吗?我怀疑您的数组中有一个空白值会触发BadUriFormat异常 -
天哪。我有一种感觉,这很愚蠢。我的第二个
recipe没有:image_link。
标签: ruby-on-rails ruby-on-rails-4 url uri