How to write this Rails asset pipeline link - ruby-on-rails-4

Rails 4.2
This asset pipeline stuff I continue to not figure out.
How would I write this?
<!-- For image lightbox you need to include "a" tag pointing to image link, along with the class "prettyphoto".-->
<div class="gallery">
<!-- Full size image link in anchor tag. Thumbnail link in image tag. -->
<img src="img/portfolio/1.jpg" alt="" class="img-responsive">
I've tried it twenty ways but I can't get it. A small image is suppose to come up and then when you click on it the image is larger. And I need to use the two existing classes as this is a bootstrap template conversion into Rails.

If it's in public/assets/images you can access it by saying:
<%= image_tag 'name_of_image.png', class: 'name-of-class' %>
http://apidock.com/rails/ActionView/Helpers/AssetTagHelper/image_tag
<%= link_to 'name_of_image.png', object_path, class: 'name-of-class' %>

Related

Generate PDF based on Particular Div id in Rails

Is there a way to generate pdf in rails based on div id.
Sample code:
<div id="pdf_download">
<h1>Hello Welcome to PDF
</div>
<div id="seconf_pdf">
<h2>Second PDF</h2>
</div>
Now i want to download only the div id "pdf_download" as pdf, Is it possible? Can anyone explain how to achieve it?
There seems to be a gem that does that - wicked_pdf. Internally it seems to depend on wkhtmltopdf, so you should be able to install this on your production environment.

SilverStripe Using Field Values in Template

all! So I'm brand-spankin' new to SilverStripe, and while I've had success in modifying the 'Gallery' module to include an option to set the thumbnail size, I'm having issues using the thumbnail width/height values in my template. The code below does not show any of the gallery images (if I hardcode a width and height, such as 250,250 they display)-- but after the loop where I display the $ThumbWidth and $ThumbHeight values, those are displaying just fine...so I know those values are available to the template.
<% loop OrderedImages %>
<a class="fancybox" data-fancybox-group="gallery" href="$Filename" title="$Caption">
$SetSize($ThumbWidth, $ThumbHeight)
</a>
<% end_loop %>
Width: $ThumbWidth
Height: $ThumbHeight
So apparently, the $SetSize function is not liking the values I'm passing to it. Can someone shed some light on where my mistake is?
Thanks!
Bryan
From the SilverStripe forum:
Those variables are not set on the OrderedImage item which is the context of the loop. Use $Top.ThumbWidth and $Top.ThumbHeight as parameters.

How to display a youtube embed link that is called from database

I have an application I want to use for my teaching studio where I create lessons that students can view. the lessons are specific to each student so they are linked via a :user_id (user has_many lessons, lesson belongs_to user). I can bring up specific lessons based on which user it is but the one part I cannot figure out is how to get a video (youtube) link to display correctly. What I want is to save the link along with the text for the lesson. The text and title and all that comes up fine right now, but the video will not display with embed code and throws a routing error in the iframe window.
Here is my code for the _lesson partial. "video_url" is the name of the column in the database.
_lesson.html.erb
<li>
<span class="content">
<%= lesson.title %><br />
<%= lesson.lesson_notes %>
<iframe width="490" height="275" src="<%= lesson.video_url %>" frameborder="0" allowfullscreen></iframe>
</span>
</li>
this is the code in my show view.
show.html.erb
<% if #user.lessons.any? %>
<h3> Lessons (<%= #user.lessons.count %>)</h3>
<ol class="lessons">
<%= render #lessons %>
</ol>
<%= will_paginate #lessons %>
<% end %>
the error I get is below
No route matches [GET] "/users/www.youtube.com/embed/CFF0mV24WCY"
I kind of understand what is happening, but not really. I guess I am unsure why it is looking for that route instead of just embedding the code and then displaying the video. It brings up all the other text and stuff from the lesson so that is working fine. Is there not an easy way just to display the link so it embeds the video along with it? I have searched quite a bit but everything I find just deals with embedding the code into the html which I can do, but this needs to change based on the user so has to be pulled out of the database along with the rest of the lesson info. Any help would be greatly appreciated.
src needs to know the protocol, so if you don't include http://, the explorer assumes that the given src is next to your actual path.
A shitty solution could be add the protocol with a raw string:
src="http://<%= lesson.video_url %>"
But a way better solution is adding a filter to check if the protocol is included when you save the field.

How to use multiple favicon.ico sizes with favicon_link_tag helper in rails 4

My problem is simply the favicon not showing up when using the favicon_link_tag and the multiple sizes option.
<%= favicon_link_tag 'favicon.ico', sizes: '16x16 32x32' %>
The files were labeled favicon-16.ico and favicon-32.ico respectively. These images are in the app/assets/images folder. Am I labeling them wrong? Is this a limitation?
The solution does not lie in Rails magic but in the way you manage the favicon.ico file. A single ICO file can contain several pictures. This is what web browsers expect. In particular, favicon.ico should contain three versions of the same icon: 16x16, 32x32 and 48x48. Regarding the sizes attribute, it was introduced in HTML5 and is dedicated to the PNG icons. Not favicon.ico.
The code
The basic definition is enough:
favicon_link_tag '/path/to/favicon.ico'
Make sure the path is consistent with app/assets/images, I must admit I don't know where it is mapped.
The picture
You can first prepare three PNG pictures (let's call them 16x16.png, 32x32.png and 48x48.png) and merge them with a tool such as icotool (on Ubuntu: sudo apt-get install icoutils):
icotool -c -o favicon.ico 16x16.png 32x32.png 48x48.png
If you don't want to bother with icotool and you don't have any other solution at hand, you can also use this favicon generator. Just keep the generated favicon.ico and leave the rest if you are not interested. Full disclosure: I'm the author of this site.
One idea would be to use the the link philippe_b posted to generate the various images. Place them in app/assets/images/
Then, in your application.html.erb put the following code between the <head> </head> tags in your application:
<% %w(57 60 72 76 114 120 144 152 180).each do |s| %>
<%= favicon_link_tag "apple-touch-icon-#{s}x#{s}.png", rel: 'apple-touch-icon', type: 'image/png', sizes: "#{s}x#{s}" %>
<% end %>
<% %w(16 32).each do |s| %>
<%= favicon_link_tag "favicon-#{s}x#{s}.png", rel: 'icon', type: 'image/png', sizes: "#{s}x#{s}" %>
<% end %>
This will allow you to use the assets precompiled in app/assets/images/ without having to place them in app/public/
Please note that I am not dealing with the Android or Windows images here, only basic favicon and apple touch images. For more information on suggested apple touch icon sizes, check this website.

can't add a link to an entire div section

I have a problem with TinyMCE in Joomla 2.5.4. I have tried for a few days now to add a link to a div section (like <div> something< </div> ) but failed, the anchor is stripped from the HTML section because TinyMCE sees that as being wrong in HTML4. After a 3 days research I gave up and instead of a div i used a unordered list.
Now when i try to add a link to a list item (like <li> <p> something </p> </li> ) TinyMCE rearranges everything and moves the anchor inside of the list item (like <li> <a href="#"> <p> something </p> &=lt;/a> </li>).
I have tried pretty much everything from valid_elements : "[]" to text filter: No Filtering but i ran low on ideas.
Can anyone please help me?
Try playing around with TinyMCE's html5 options: http://www.tinymce.com/tryit/html5_formats.php
Hit "view source" to see how they're doing it. It's mainly this option inside tinyMCE.init:
schema: "html5",