ruby-on-rails - 文章中的参数错误
问题描述
将图像上传到页面后,我在 Articles#show 视图中收到此 ArgumentError。Can't resolve image into URL: undefined method `to_model' for # 你的意思是?to_yaml
<% if @article.photo.present? %>
<%= image_tag(@article.photo, style:"width:100%") %>
<% else %>
<%= image_tag 'banner.png', style:"width:100%" %>
<% end %>
这也是我在文章控制器中的私有方法:
private
def article_params
params.require(:article).permit(:title, :text, :search, :music, :movie, :photo)
end
解决方案
因为你使用回形针,这条线是你的错误的问题
<%= image_tag(@article.photo, style:"width:100%") %>
您可以在您的文章模型(app/models/article.rb)中检查回形针中的格式设置,通常它形成为缩略图、中等、原始,您可以使用下面的示例编写代码
<%= image_tag(@article.photo.url(:original), class: "thumb-style") %>
在你的 CSS 文件中
.thumb-style {
width: 100%;
}
推荐阅读
- python - 如何通过 nbconvert API 设置参数“--template toc2”?
- python - 如何在 QtCharts 中添加子图?
- vba - .AddNew Record 与多选组合框
- javascript - 版本 3 的 Mathjax 实时预览
- python - 两个列表之间的减法差异
- html - 由于某种原因在页面加载时开始转换
- reactjs - 警告:使用 `defaultValue` 或 `value` 道具
- python - 在使用 Selenium 的 Web 自动化过程中加载带有 PyQt5 冻结问题的动画
- mql4 - MQL4 EA 忽略一些箭头
- javascript - Socket.io 为 `on` 侦听器提供多个处理程序,如 Express