How to display a youtube embed link that is called from database - ruby-on-rails-4

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.

Related

How to write this Rails asset pipeline link

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' %>

Kentico - New fields on existing document types won't render

In Kentico 7, I added 3 new fields to the Page (menu item) document type: small_desc, long_desc and icon_class - this is in addition to the existing fields MenuItemID, MenuItemName and MenuItemTeaserImage.
On a Repeater WebPart I added the following transformation:
<li class="...">
<a class="<%# Eval("icon_class") %>" href="<%# GetDocumentUrl() %>">
<%# Eval("MenuItemName") %>
</a>
<p class="..."><%# Eval("small_desc") %></p>
</li>
A strange thing happens. While viewing the page with the Repeater in Preview mode, everything renders correctly:
<li class="...">
<a class="unique_class" href="/url.htm">
Document Title
</a>
<p class="...">A description I just added to the document.</p>
</li>
But in Live mode, I see:
<li class="...">
<a class="" href="/url.htm">
Document Title
</a>
<p class="..."></p>
</li>
So...
We've run through a plethora of troubleshooting steps...
there are absolutely no exceptions in our Event Log
everything is checked in
server cache cleared
application restarted
browser cache cleared and hard reloaded on multiple browsers and machines
My assumption was Kentico didn't like it when you add new fields to existing (Kentico default) document types. I cloned a completely new document type earlier, added all brand spanking new fields, ran a repeater on a list of new documents, and every single field showed up. I'm certain I could do that - just clone Page (menu item) and recreate all of my pages, but for (I hope) obvious reasons I'm not going to do that. Kentico Support hasn't been able to give any good direction so I turn to you smart folks!
What are the columns set in the repeater's Columns property? Isn't it possible that there are set some of them and you are missing the new ones? If it is blank, all the columns should be loaded (not good for performance though).

Dropdown Menu Populated by Database

Currently I have a model Abc. It has a column in it's associated database called 'description'. I'm trying to figure out how to populate a dropdown menu with the contents of the description so that the user would be able to select through each of the choices and pick one.
Currently, my action in my controller has this:
#abc = Abc.all
As far as I understand, this should select all records in the database that is associated with the model Abc.
Then, in the view associated with this action, I have this:
<select name="id">
<%= #abc.each do |abc|%>
<option value="<% abc.id %>"><%= abc.description%></option>
<% end %>
The above is something I was trying to adapt off an example I found online, which isn't working. I think this is supposed to create a dropdown menu with option values set to ID of the database entries. Then the actual content of the dropdown menu is populated with the contents of the 'description' column of the database. This isn't working as of now. Currently giving me this error:
undefined method `each' for nil:NilClass
on the:
<%= #abc.each do |abc|%>
line of code.
The example I was talking about is here:
<select name="user_id">
<%= #users.each do |user| %>
<option value="<%= user.id %>"><%= user.name %></option>
<% end %>
</select>
The context of the example is here: http://www.theodinproject.com/ruby-on-rails/advanced-forms
I'm pretty new to rails, any help would be appreciated. I get the feeling that I'm misunderstanding something about rails itself since the 'each' method is rails' version of an iterator.

Incorporating slideshow / carousel into custom tumblr theme

Got a very particular problem here:
I've been developing a tumblr-hosted site locally, using the API to pull in posts without having to copy and paste the project into tumblr a million times. I decided I liked the API better and would just use that in production, but now that it's time to deploy I realize that I have to go back to the custom theme, {block:Posts} method.
I have the post feeding into a Cycle2 slideshow, with 3 slides containing 3 posts each for a total of 9 playlists viewable without going back to the archive. This method works perfectly with the api, but is getting messed up in the custom theme. Here's my current code:
<div class="cycle-slideshow">
{block:Posts}
{block:Text}
<div class="slide-wrapper">
<div class="post">
{block:Post1}
{block:Title}<h2>{Title}</h2>{/block:Title}
<div class="blog_item">
{Body}
</div>
{/block:Post1}
</div>
<!--two more posts before end of slide... -->
</div>
{/block:Text}
{/block:Posts}
</div> <!--end of slide wrapper - 2 more of these before end of slideshow div..
I also tried scrapping the post numbers, but still no dice. In tumblr's docs, they say that
Example: {block:Post5}I'm the fifth post!{/block:Post5} will only be rendered on the fifth post being displayed.
I'm wondering if "being displayed" refers to the html visibility of the post, and if so, if that's interfering with the cycle plugin? The results are one ill-formatted post per slide, and then after cycling through 2 blank slides, the next oldest post takes its place. I'll be pleasantly surprised if anybody has ever had a similar problem but I would kill for some advice. Here's the development site for reference (and the second carousel is working because it's still hooked up to the api). thanks!!
Generally speaking, the following code is what you'd want to have 3 slideshows with 3 posts each.
Note that in the Additional Settings on the Customize screen, you'd have to set the post count to 9 per page in order for this to work properly. I wrapped it in an Index Page block, otherwise this is going to look nasty on a Permalink Page.
{block:IndexPage}
{block:Posts}
{block:Post1}<div class="cycle-slideshow">{/block:Post1}
{block:Post4}<div class="cycle-slideshow">{/block:Post4}
{block:Post7}<div class="cycle-slideshow">{/block:Post7}
<div class="slide-wrapper">
{block:Text}
<div class="post">
{block:Title}<h2>{Title}</h2>{/block:Title}
<div class="blog_item">
{Body}
</div>
</div>
{/block:Text}
{block:Photo}
...
{/block:Photo}
...
</div>
{block:Post3}</div>{/block:Post3}
{block:Post6}</div>{/block:Post6}
{block:Post9}</div>{/block:Post9}
{/block:Posts}
{/block:IndexPage}
However, if you're wanting 3 slideshows with the post types split between the slideshows, the code would look more like the following.
Note that in this scenario, if you were to have 4 texts posts out of 9, all 4 text posts would end up in the Text slideshow. You'd have to use Javascript or CSS to remove or hide the additional posts if you're very strict about your 3.
{block:IndexPage}
<div class="cycle-slideshow">
{block:Posts}
{block:Text}
<div class="slide-wrapper">
<div class="post">
{block:Title}<h2>{Title}</h2>{/block:Title}
<div class="blog_item">
{Body}
</div>
</div>
</div>
{/block:Text}
{/block:Posts}
</div>
<div class="cycle-slideshow">
{block:Posts}
{block:Photo}
<div class="slide-wrapper">
...
</div>
{/block:Photo}
{/block:Posts}
</div>
{/block:IndexPage}
If you need me to clarify anything, let me know.

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",