carrierwave image not loading into source code

2019-08-13 01:15发布

问题:

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.