Embed web page coded in Ruby on Rails in another web site?

Viewed 6449

I would like to make my web page that I coded with Ruby on Rails as backend embeddable so that users are able to easily share it by copy and pasting some embed code. (much like YouTube embed code, but for a webpage) Could someone point me to a tutorial or general direction how to go about doing so? I'm planning to embed my web page in Joomla CMS.

Many thanks.

Pier.

3 Answers

A bit late, but I stumbled over this Question while searching for a solution by myself. I found a Gem that does exactly what's described. It will make your rails app embeddable like YouTube Videos or Content from other Webpages like Google Maps, Instagram, Twitter… It's called EmbedMe

To use you simply need to change your Routes to define, which Paths need to be embeddable

get 'private', to: 'application#private'
embeddable do
  get 'embeddable', to: 'application#embeddable'
end

Gem on Github or Documentation

In case anyone is coming across this now, almost 9 years later...

If you use the JavaScript method, you'll have to allow Cross-Origin requests, like @abessive mentioned in their comment above. I was able to do this by adding this to the top of my controller class:

protect_from_forgery except: :method

where :method is the method that will be called for the embed request.

Here's my controller:

class PagesController < ApplicationController
  protect_from_forgery except: :home

  def home
    render 'index.js'
  end
end

And the relevant route in routes.rb:

get "index.js", to: "pages#home"

And I have views/pages/index.js.erb with some JS code that renders the widget.

(I'm using Rails 6.1.4)

Related