I am trying to insert image in student report, edited the below code and it shows the default image but when I upload the student image it doesn't show it.
<% if #student.photo.file? %>
<%= wicked_pdf_image_tag #student.photo.url %>
<% else %>
<%= wicked_pdf_image_tag "master_student/profile/default_student.png" %>
<% end %>
Related
<%best_sellers = Spree::Taxonomy.find_by_name("Best Seller").root.products.limit(6)%>
<%best_sellers.each do |best_seller_array|
<div class="card card-custom text-center rounded w-25">
<%= image_tag main_app.url_for(best_seller_array&.attachment),class:"img-fluid" %>
<%= best_seller_array.name%>
</div>
<%end%>
In spree, product has_many :images, so if you want to display any product image, you can try something like below -
<%= image_tag main_app.url_for(product&.images&.first&.attachment), class: "img-fluid" %>
and if you want to display all the images of the product, then simply traverse the loop of images like below
<% best_sellers_products.each do |product| %>
<% product.images.each do |image| %>
// display image
<% end %>
<% end %>
Hope this will solve the problem.
Thank you
I am having an issue getting a collection of user posted pics to show using paperclip. From the code you'll see that the app allows either a link or a file to be shown. It Works just fine showing all on pics/index but the papercliped files won't show in the user collection users/1/pics. I believe it has something to do with the way Rails puts the path in the image_tags.
Routes
resources :users do
member do
get :pics
get :toggle_approve
end
User/show
<% if #user.pics.any? %>
Pics Posted: <%= link_to #pics.count, pics_user_path(#user) %>
<br />
<% else %>
No Pics Posted!<br />
<% end %>
Pics/index
<% #images.each do |image| %>
<% if !image.image_link.nil? %>
<li><%= link_to image_tag(image.image_link, size:"100x200"), pic_path(image), class: "th" %><br>
<% else %>
<li><%= link_to image_tag(image.image.url(:large), size:"100x200"), pic_path(image), class: "th" %><br>
<% end %>
<% end %>
EDIT
I figured it out. The users view for the pics /user/1/pics had similar code as the pics/index. When I added the functionality for the paperclip uploaded file, I didn't update the user pics view with the same logic to determine if it was a link or a file.
I am trying to have a link to a pdf file on a website. When someone clicks on the link, it should open the pdf file up in a new browser window.
I have the following code in the view:
<% #filtered_portfolio_files.each do |the_file| %>
<li>
<% if the_file.is_picture? %>
<%= image_tag(the_file.port_file.picture) %>
<% else %>
<%= link_to image_tag('/assets/pdf_image.png'), the_file, target: '_blank' %>
<% end %>
</li>
<% end %>
This should show the image if the file is an image or a dummy picture of the Adobe PDF logo that links to the pdf file if the file is a PDF.
Right now this loop goes through two files. The first is an image and the 2nd is a PDF. It correctly shows the first image and the 2nd correctly shows an image of the PDF logo, but when clicked on it brings me to a page that says
No route matches [GET] "/portfolio_files/4"
I have also tried in the view:
<% #filtered_portfolio_files.each do |the_file| %>
<li>
<% if the_file.is_picture? %>
<%= image_tag(the_file.port_file.picture) %>
<% else %>
<%= link_to image_tag('/assets/pdf_image.png'), the_file.port_file, target: '_blank' %>
<% end %>
</li>
<% end %>
but that stops the page from loading and returns the error:
undefined method `model_name' for PortfoliofileUploader:Class
How do I get the PDF link to correctly link to correctly link to the pdf file?
<%= link_to image_tag('/assets/pdf_image.png'), the_file.port_file.url, target: '_blank' %>
Add a .url on the end.
I am using paperclip in my rails app. I want to use an image uploaded via paperclip if an attribute appears for the field and use another image if it doesn't. With this code, the first portion of the if statement always executes regardless of whether there is an entry in the logo field. Any advice?
<% if #product.logo.url %>
<%= image_tag #product.logo.url, :style => 'width:60px;' %>
<% else %>
<img src = '/assets/logo/<%= #product.slug.downcase %>-sq.jpg' class="img-circle" style = 'width:60px;'>
<% end %>
You probably want to try calling String#blank?:
<% if #project.logo.url.blank? %>
<%= image_tag #product.logo.url, :style => 'width:60px;' %>
<% else %>
<img src = '/assets/logo/<%= #product.slug.downcase %>-sq.jpg' class="img-circle" style = 'width:60px;'>
<% end %>
I'm very new to programming and have followed this screencast at emersonlackey.com on adding multiple paperclip uploads for a record. It all works great but I can't figure out how to display the uploaded images in the records show page.
They display fine on the edit page using:
<%= f.fields_for :venuephotos do |photo| %>
<% unless photo.object.new_record? %>
<p>
<%= link_to image_tag(photo.object.venuephoto.url(:thumb)), photo.object.venuephoto.url(:original) %>
<%= photo.check_box :_destroy %>
</p>
<% end %>
<% end %>
I've used paperclip in other models but they are the standard each record only has one upload so the images display fine with <%= #model.photo.url %> type call but I cant figure out this other way.
Any help is much apprectiated!
You want to do something like this:
<% for asset in #post.assets %>
<%= link_to image_tag(asset.asset.url(:thumb)), asset.asset.url(:original) %>
<% end %>
as per the code that goes along with the screencast.
https://github.com/Emerson/Multiple-File-Uploads-with-Paperclip-and-Rails-3/blob/master/app/views/posts/show.html.erb