0

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?

Daniel Bonnell
  • 4,817
  • 9
  • 48
  • 88

1 Answers1

2

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.

Community
  • 1
  • 1
p4sh4
  • 3,292
  • 1
  • 20
  • 33
  • 1
    Thanks for the insights. I actually found what may be a more ideal solution. Since I'm linking to a WordPress site, it looks like it is possible to set up the blog in a subdirectory and incorporate it into the rails router. I'm going to test this idea out and see if it works. Also seems more optimal for SEO purposes. Here's [the blog post](http://rywalker.com/setting-up-a-wordpress-blog-on-heroku-as-a-subdirectory-of-a-rails-app-also-hosted-on-heroku/) that outlines the process. – Daniel Bonnell Apr 29 '15 at 16:03