Daniel Bonnell
Daniel Bonnell

Reputation: 4997

Embed external website in Rails template

I have a Rails site and an externally hosted WordPress blog. I want to be able to send users to mysite.com/blog and have them hit the blog. I can do that pretty easily with a redirect. But then they are no longer on my main site.

What I really want is to render the blog inside my main template, so that the navbar from my site remains on the page, and the url stays as mysite.com/blog. Ideally, when they clicked on a link in the blog, it would render inside the template, but the navbar and url from the rails site would remain intact.

Is this possible?

Upvotes: 0

Views: 660

Answers (1)

p4sh4
p4sh4

Reputation: 3291

There are a few ways to do this. Some examples:

  1. Iframes come to mind first. Frowned upon in modern web development, see this question for lots of reasons, but is probably the simplest way.
  2. Jquery .load(), or just a basic ajax call. Note that because of the same origin policy, it won't work if you're trying to retrieve from another domain. A workaround would be to include something like this in your Wordpress site to explicitly allow requests from your Rails site: <customHeaders> <add name="Access-Control-Allow-Origin" value="http://your-rails-site.com" /> </customHeaders>
  3. HTML imports

There are some other ways including but not limited to <object> and <embed> tags. I would suggest to research them and find the best solution for your use case.

Upvotes: 2

Related Questions