Rails 3 rendering iframe with raw() - ruby-on-rails-3

So I am storing the whole embed code from youtube into my database and then outputting it like this.
<%= raw(people.video) %>
which outputs the general iframe tag copied from youtube:
<iframe src="foo" width=400 height=380></iframe>
the problem is that it actually displays that tag instead of embedding the video into the page itself. I can get around this just by storing the src in the database.... but this is part of a mini cms system and the site admins would find it much easier just to copy and past the embed code from youtube. Is there someway I can specify for the iframe to actually render instead of just spitting out the html on the page?

You can use the raw method to render the HTML of a string, are you storing it that way? You can also try the RedCloth gem - I was able to get this working like so:
<%= raw RedCloth.new(#page_content.content).to_html %>
Which allowed for my custom CMS to use the Textile markup
http://en.wikipedia.org/wiki/Textile_%28markup_language%29
I'm not 100% on what you're seeing, since raw should render HTML, but you might also try to include the embed tag using a JavaScript.write, since there are some issues related to Flash objects embedded in HTML vs JavaScript.
Let me know if this doesn't work, and if so, can you provide screenshots or copy what you're seeing on the page?

Related

Serving Image Assets From a CDN in a Simple Rails Blog

I have a feeling this is a simple question that I'm just missing something, but I've thought about it and Googled a bit and haven't come up with anything yet.
I am running a Rails app on Heroku, using the asset pipeline, and serving static assets through a CDN using asset_sync. However, for my super simple blog I realized that it's serving assets through the app itself because I simply call in my view:
<%= #blog.body %>
The blog model is title (string), body (text), description (string). And the body is just a text blob of html. So for an image I'd include a line like the following as part of #blog.body:
<img alt="Clever alt tag" src="/assets/blog/my_image.jpg">
Is there a way to use this simple approach but have the image assets served from the CDN instead of the Heroku app?
You probably need to write your blog post using something like ckeditor, which can play nicely with the asset pipeline.

Rails3. Is there any way to separate javascript file for different controllers?

I search around for quite some time but there's are no close solution for this.
For example,
I had generated 2 controllers: Articles, and Calendars.
There have been 2 javascript files also been generated according to these 2 controllers as:
calendars.js and articles.js.
The problem is, if they (2 files) all are included into application.js without any condition. i.e when I open articles/index action, the calendars.js has been imported on page
or when I open calendars/index action (or any action), the articles.js has been imported on page.
What I am looking for is a methodology to separate javascripts file according to the controller that they are belong to?
I also having the same question related to css files.
Thank you and Best regards,
Dat
What you probably want to do is only execute certain pieces of javascript on each controller (action). You can achieve that easily with this gem: https://github.com/intrica/rails_document_ready.
You can add in your index.html.erb file.
For the specific page where you want this js file add in your html file.
<%= javascript_include_tag "articles" %>
I found paloma: https://github.com/kbparagua/paloma
I develop new Rails application for about 2 months with this gem, and it provide quite effective way to manage javascript.

Rendering an HTML file in rails

I am using CarrierWave to upload static HTML templates to certain user profiles on my webpage.
I am trying to render the HTML file on the user's home page once they log in. The Path for the HTML file after uploading is:
/uploads/profile/curation/8/User_Content.html
I'm new to rails and I thought I'd just be able to
<%= render /uploads/profile/curation/8/User_Content.html %>
to get the html to render, but I guess that only works for partials, which this is not.
Any advice?
You can use render_to_string. Please have a look over here. http://russbrooks.com/2009/11/18/embed-a-static-hmtl-page-in-a-rails-view
In your controller you can redirect to the page you want:
redirect_to "/uploads/profile/curation/8/User_Content.html"

Checking the contains of an embed tag using Selenium

We generate a pdf doc via a call to a web service that returns the path to the generated doc.
We use an embed html tag to display the pdf inline, i.e.
<div id="ctl00_ContentPlaceHolder2_ctl01_embedArea">
<embed wmode="transparent" src="http://www.company.com/vdir/folder/Pdfs/file.pdf" width="710" height="400"/>
I'd like to use selenium to check that the pdf is actually being displayed and if possible save the path, i.e. the src link into a variable.
Anyone know how to do this? Ideally we'd like to be able to then compare this pdf to a reference one but that's a question for another day.
As far as inspecting the pdf from selenium, you're more or less out of luck. The embed tag just drops a plugin into the page, and because a plugin isn't well represented in the DOM, Selenium can't get a very good handle on it.
However, if you're using Selenium-RC you may want to consider getting the src of the embed element, then requesting that URL directly and evaluating the resulting PDF in code. Assuming your embed element looks like this <embed id="embedded" src="http://example.com/static/pdf123.pdf" /> you can try something like this
String pdfSrc = selenium.getAttribute("embedded#src");
Then make a web request to the pdfSrc url and do (somehow) validate it's the one you want. It may be enough to just check that it's not a 404.

Keeping DRY with progressive enhancement

I'm building a website with very small amounts of Javascript, just to add things to the page (like a contact form) without having to go to a new page.
I understand that I should build the contact page anyways (just in case the user doesn't have javascript turned on) and then use javascript if they've got it.
So where do I store the HTML for the form if I don't want to have it in two places?
(Normally I'm not so picky, but I'm curious on this one.)
If you have access to a server-side language, you can keep a separate snippet of the form in an external page. Then, you can include the snippet into the HTML content page with an appropriate include call. This has the added benefit that, for your JavaScript, you can pull the contact form from this snippet file using AJAX. In fact, many plugins allow you to display DHTML windows with HTML content. For example, check out ThickBox.
Without a server-side language, you can do something similar with frames. Just display the form snippet in a frame when you need to reference it. Personally, I don't like frames very much, so this isn't a very attractive solution for me, but you can use it if you choose (and style the frames appropriately).
Just put your HTML for the contact form in a .html file. Assuming you're using PHP or something, just include the file in your contact page and include it in the section for your dynamic contact form. The form should still submit to the same server-side page and have the same look and feel..
e.g. contactForm.html
<div class="contact-form">
<input ....>
</div>