载波图像未加载到源代码中 [英] carrierwave image not loading into source code

查看:70
本文介绍了载波图像未加载到源代码中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不知道我在这件事上做错了什么。我遵循了Carrierwave的Rails Cast,但遇到一个奇怪的错误,根本没有显示图像-(HTML)源代码显示了图像标签,但里面没有任何内容。

Not sure what I'm doing wrong on this one. I've followed the Rails Cast for Carrierwave but am having a strange bug where the image isn't showing at all - the (HTML) source code is showing the image tag but nothing inside it.

投资组合模型代码:

 class Portfolio < ActiveRecord::Base
  validates :title, :content, presence: true
  mount_uploader :feature_image, FeatureImageUploader   
end

功能图片上传器代码:

class FeatureImageUploader < CarrierWave::Uploader::Base
 storage :file

 def store_dir
  "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
 end

 def extension_white_list
  %w(jpg jpeg gif png)
 end
end

Show.html.haml代码:

Show.html.haml code:

= @portfolio.title
=image_tag @portfolio.feature_image_url.to_s
=markdown(@portfolio.content).html_safe

我的表单代码:

.field
 = f.label :title
 %br
 = f.text_field :title

.field
 = f.label :date
 %br
 = f.datetime_select :date

.field
 = f.label :content
 %br
 = f.text_area :content, rows: 10

.field
 = f.label :feature_image
 = f.file_field :feature_image

.actions
 = f.submit

我的HTML源代码显示:

And my HTML source code is showing:

<img src=""/>

我已经进行了耙测试,一切都很好,没有失败。

I've run my rake tests and everything is fine, no failures. Would someone mind having a look for me, would really appreciate it.

谢谢!

编辑

这是我在添加新投资组合条目时从服务器日志中粘贴的信箱- http://pastebin.com/1zNxB975

This is my pastebin from the Server logs when I add a new portfolio entry - http://pastebin.com/1zNxB975

推荐答案

=image_tag @portfolio.feature_image.url

和控制器

portofolios_controller.rb

...
private
    def portofolio_params
      params.require(:portofolio).permit(:title, :date, :content, :feature_image)
    end

不确定您可能拥有的其他参数以及需要,但是:feature_image 是必须的。

not sure about the other params you might have and need, but :feature_image is a must.

这篇关于载波图像未加载到源代码中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆