Rails 5, "Nil Is Not a Valid Asset Source"

Rails 5, nil is not a valid asset source

The problem was that I was trying to show an image that did not exist.

Adding unless article.image.blank? solved it:

<%= image_tag article.image_url(:thumb) unless article.image.blank? %>

EDIT: In Rails 4, this would have just rendered nothing without errors, while in
Rails 5 it raises an error. So it was, in fact, an upgrade issue.

Big thanks to @BookOfGreg for pointing this out.

Rails 5 CarrierWave error nil is not a valid asset source

Change your method to accpet image param well

 def profile_params
params.require(:profile).permit(:name, :bio, :born)
end

to

 def profile_params
params.require(:profile).permit(:name, :bio, :born, :image)
end

As well check you should install gem 'mini_magick'

.first gives error when there's only none/one image

I guess the ternary operator would help here:

<%= image_tag product.images.any? ? product.images.first : product.image %>

or even simpler, using logical OR operator, as @mudasobwa noticed:

<%= image_tag product.images.first || product.image %>

Carrierwave avatar uploading params

ActionView::Template::Error (nil is not a valid asset source): 4: <div class="panel panel-default"> 5: <div class="panel-body"> 6: 7: <%= image_tag current_user.avatar.url%> 8: </div> 9: </div>

Why are some reasons that payments.valid.first.source return nil for Spree::Order?

It all depends on the payment gateway you're using. Even if it's a CC based payment gateway there are some that don't persist CC as a source in Spree.

Each Payment Method in Spree has a method called source_required?: https://github.com/spree/spree/blob/a01ffd29b73f75cb234fcf5d368fb23553acf4d1/core/app/models/spree/payment_method.rb#L49

You should check if the one you are using returns true.

Image is not uploading from public/asset to the page, giving connection error in Rails via Carrierwave

I have found the problem and would like to write down the solution for who might have the same problem in the future...

I was following instructions of the following article because my course recommended that one: https://blog.thefirehoseproject.com/posts/switching-carrierwave-to-use-s3-with-heroku-and-localhost/

*but this is quite old one!

I was getting the error about connecting to S3server. While arranging the 'Permissions, while creating a user for Amazon IAM Dashboard, you should make three first 'off' and last one 'on'. So, you can upload images.

Block all public access -> Off

  • Block public access to buckets and objects granted through new access control lists (ACLs): Off
  • Block public access to buckets and objects granted through any access control lists (ACLs): Off
  • Block public access to buckets and objects granted through new public bucket or access point policies: Off
  • Block public and cross-account access to buckets and objects through any public bucket or access point policies: On

Happy coding!

Rails - Asset is not present in asset pipeline when using image_tag

The asset "aussen" is not present in the asset pipeline.

Technically true because you have not aussen but you have aussen.jpg so it will be <%= image_tag("aussen.jpg") %>

Look, while you use <%= image_tag("aussen") %> then it will be genarate HTML like this

<%= image_tag("aussen") %>
#=> <img alt="Aussen" src="/assets/aussen" />

While you use <%= image_tag("aussen.jpg") %> then it will be genarate HTML like this

<%= image_tag("aussen.jpg") %>
#=> <img alt="Aussen" src="/assets/aussen.jpg" />

When it's going into production mode then it will be shown some encrypted key on the page source like this

aussen-d2fb0029a12281121a1752c599e715a8e2b3db17f1e8e18248a79a7b1ca63b91.jpg

image_tag AssetTagHelper see this for reference.

Update production.rb file config.assets.compile false to true

# config/environments/production.rb
...
config.assets.compile = true
...


Related Topics



Leave a reply



Submit