carrierwave image not loading into source code

 ̄綄美尐妖づ 提交于 2019-12-24 15:05:59

问题


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.

Portfolio Model code:

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

Feature Image Uploader code:

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 code:

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

And my form code:

.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

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.

Thank you!

EDIT

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


回答1:


in views

=image_tag @portfolio.feature_image.url

and controller

portofolios_controller.rb

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

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



来源:https://stackoverflow.com/questions/21110497/carrierwave-image-not-loading-into-source-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!