Ruby on Rails integrated with Wordpress site - ruby-on-rails

I'm working on an Ruby on Rails exercise listing application (https://rbzexercise.herokuapp.com) and I'm trying to integrate it with a Wordpress site (http://www.rubberbanditz.com). Is there an easy way to do the integration? As you can see, both are pretty established, so I'd really prefer not to have to rewrite either. Right now i'm using a work around that involves an iframe within the page http://rubberbanditz.com/exercise-library/, but we don't get any of the "google juice" from it.
Update:
Based on the comments, I've started looking into integrating the app to exercise.rubberbanditz.com, but following the directions at https://devcenter.heroku.com/articles/custom-domains doesn't seem to be doing the job. when going to exercise.rubberbanditz.com i just automatically get forwarded to the main page. Does anyone have any experience with setting a rails app to a subdomain, and can you point me to a good tutorial?
Thanks for any help!
Jason

Your iframe method is fine, but might lead to seo problems, since all of your links are trapped in the iframe.
Another option would be to take your WordPress theme and rebuild it in your /app/views/layouts/application.html.erb template. Once that's done, make a subdomain (maybe app.rubberbanditz.com or workouts.rubberbanditz.com) and setup your heroku app to use the new subdomain.
Google should view the two subdomains as the same website, especially if you're sharing common navigation elements, and both sites link to each other frequently.
The biggest downside is that now you'll have to update your design in two different places, which can be a huge pain in the ass.

I've used this approach before, running-php-inside-a-rails-app, for running php inside a rails application. Not sure if anything extra will be required for wordpress since I was just rendering a single page.

Related

Ruby on Rails separate front & back

I've been using Ruby on Rails since a little more than one year now and I've always do it in a casual way, I mean, everything in one place (front & back), using the standard .html.erb file populated by the associated controller method.
Otherwise, today in our project, I have the need to separate the front and the back end for multiples reasons (code maintainability / clarity, better architecture, more reactivity, etc...).
I've done plenty of researches, watch some conferences (1, 2, 3), but didn't find my solution yet. It looks like to be a question that comes often, but what is the best practice/tools to separate the backend and the frontend of a Ruby on Rails app?
I don't feel we need (yet) a huge JS framework like React/EmberJS/Angular/etc...
First I was thinking about something like Middleman/Jekyll and make the communication via JSON and API calls, but it seems like that it's not a good solution for dynamic website.
So is there a frontend framework that works well with a Rails API and which is easily maintainable and upgradable (add feature/extension to it like gems)?
Thanks for your insights.
A friend of mine wrote this great article/tutorial on Rails as a backend API.
http://blog.launchacademy.com/the-basics-of-building-an-api-in-ruby-on-rails/
As well as this tutorial on Rails/Ember.js
https://github.com/diegodesouza/Project-Planner-EmberJS
You can get an idea of how it's done and implement your preferred front end framework.
Hope it sheds some light on this question.
I have a similar setup as one of the commenters on the question.
I'm using Rails mainly for just the project structure, to define some page layouts, and for ActiveRecord.
I then have my JSON APIs defined using the Grape API framework.
I have a SPA, written on AngularJS that lives in the public/ folder. It doubles as my mobile app, made possible by phonegap. If my Angular app didn't double as my mobile app, I could've possibly just used the asset pipeline to serve up the SPA. To compensate for that, I have a separate build task written in Grunt to minify/uglify my JS/CSS assets before I deploy them out to production.
I also use Comfortable Mexican Sofa for my static content pages.
It took some trial and error to get things right, but overall I find that this setup serves me pretty well.

Integrating rails & angularjs

I tried Angular, and I liked it. I've began to integrate him into my rails-app, but then appeared some doubts about architecture
Routes. I would like to navigate without refreshing the page, before i used Wiselinks gem, it's easy and cool - just install, patch link_to helper and done. But angular have his own router, and ui-router (which is cool). I want my app to be running at the browser like Opera Mini and IE, but ui-router doesn't have such callbacks as in wiselinks. I wouldn't create mobile site version - the design is adaptive yet. It means, I would use rails routing, but I want to AJAX page refreshing when it can be (progressive enchansement, yep). What do I do?
In many places, the content is rendered by Angular, i.e. a list of posts (by ajaxing json). That fast & cool on desktop, but again old browsers! I need to render it on server for them. Or I haven't?
I'm stuck. Thanks.
This would be best trip to angularjs + rails 4...
This post clear my doubts and now i m very clear about architecture, routes, controllers, model, etc..
http://www.honeybadger.io/blog/2013/12/11/beginners-guide-to-angular-js-rails
I hope this solves your DOUBTs
and to know further about angularjs visit
http://www.angularjs.org
It's not necessary that you have to use angular routing. You can use ng-controller directive to inject controllers in your view.
Angular in general is very fast. I have been using it even in mobile browsers, it works like a charm. True if do heavy $scope manipulation, things might get little slow.
Talking about old browser support, till IE8, you are pretty good, if you follow http://docs.angularjs.org/guide/ie as already mentioned by shaunhusain, but below that I am skeptical.
I wouldnt recommend using wiselinks alongside with angular. We have tried that in a production app and it took us a long time to make this work, there had been so many issues with undead scopes and other artifacts.
Therefore, we have ended up throwing out wiselinks and replacing it with a similar directive written in angular. This way its easier to avoid problems when destroying or compiling dom.

Intergrating Angular JS with rails

I need some guidance to figure out how to incorporate Angular inside rails.
Reason for choosing Rails : I like their opionated approach to do things right. Also migrations, gems are really cool.
Reason for angular : I was researching and looking for framework best suited for SPA. Backbone seem too abstract. I had choice to make between Angular & Ember. I started reading Angular first and it made sense to me. So i never went to read about ember.
Reason for Angular & Rails: I researched and tried using small scale framework like grape, slim ( Yes i use php too ). But i feel need to stick to rails for long term scope of project. And personally i like doing things rails way.
So here is where i need help,
I have rails project in Rails 4.
Sign-in , sign-up everything is created as followed in Michael Hartl tutorial. Have tweaked stuff based on my requirement.
So post-sign-in or post-sign-up steps a view from show action of users controller is rendered.
I figured i'll need different layout files so i created same for outer pages and inner pages, respectively.
I don't know how to proceed i want to make use of the angular templates and routes for my single page app ( which resides post sign-in ). I am flexible if there is another way. I just need a guide how to use angular seemlessly with rails making use of rails controller to handle my rest request and using routing provided by angular to navigate around in SPA.
Hope i am clear. Feel free to edit this.
here is a great railscasts from ryan bates: http://railscasts.com/episodes/405-angularjs
also here is the source for that railscasts you can get ideas from there:
https://github.com/railscasts/405-angularjs
I'm not familiar with SPA, but I have been working on a tutorial for integrating rails and angularjs, which I'm refining over time. It may provide some answers here - in particular I am using the angular routing to provide a single-page app as you describe: http://technpol.wordpress.com/2013/09/03/angularjs-and-rails-tutorial-index/
I would suggest you to not mix angular into your rails app. Keep both of them separate.
So you could either place the whole of your angular app in the public folder of your rails app or keep it completely away from the rails app. This is more like a service oriented architecture, where your rails app serves as a back end serving as an api and the front end(Angular app) consuming that api.
There are many many nice articles the covers how to handle the authentication/authorization
in angularjs with REST APIs.Authentication with AngularJS and a Node.js REST api
Coming to the rails side for building REST API, Grape is a nice choice. Here is a nice series explaining some best practices about grape.
HTH!
I'd suggest taking a look at this tutorial: How to Wire Up Ruby on Rails and AngularJS as a Single-Page Application. I have used it for a few personal projects, so I am sure that it is up to date as of late 2014. If you want to view it in action you can head to http://goodmatches.herokuapp.com, and you can view the repo.
Try half-pipe gem which makes using bower for managing javascripts assets much easier.

Does it sense to use Ember 1.0RC1 with jQuery mobile in a single page web app?

I've been trying to figure out the best way to use Rails, Ember 1.0RC and jQuery mobile but with no success.
I'm building a simple single web app with Rails as a backend that provides simple JSON. Now I know that Ember and JQM don't like each other and you have to write custom helpers to render Ember views. This makes things quite complicated.
I know that there are a few examples out there but they are quite obsolete since Ember was under heavy development and there have been many changes.
I'd like to hear from experienced developers if it is a good idea or not to use Ember with JQM in my case?
Maybe I should go for other MVC framework (which one?)?
Sorry for the question being pretty open but I could not find any reliable resources on the web.
// edited on March 20
I've watched 2 Ember screencasts (from Peepscode and Railscasts) and they shed some light on the matter. Now I know a little bit more. But let me explain what I'm after.
I'm building an internal 'kudos' app based on the merits system. That is every Monday an employee receives 20 'kudos' to give other co-workers. The design is as follows:
the main page shows a list of all employees and at the top, also as an list item, there is position that belongs to himself. It shows for example how many kudos to give left and how many he or she received from others. The owner? do not know how many kudos other employees received. But I think there'll be a 'Top 3 kudoers' page.
When you tap/hold an item, a modal dialog will appear that will ask you if you what to give a kudo.
It is done. But what remained is porting it to Ember.
Now, after watching screencasts I kind of know what to do, but what buggs me is how to make JQM internal hash pages and Ember router a breeze.
I saw that one page app in Ember uses urls like these:
myapp/#/users/user
whereas JQM uses internal pages like this:
myapp/#somepage
I'd like to keep the app as simple as possible (following Ember 'convention over configuration') and make use of JQM internal pages.
So my question is how can they both go with each other?
I'd like to hear from experienced developers if it is a good idea or not to use Ember with JQM in my case?
I've been asking around about this and pretty much everyone who has tried to use JQuery Mobile with ember has advised against it.
Not that it can't be done. It's just that most people have determined the challenges outweigh the benefits. Especially if you are new to one or both frameworks.
The best example of JQM + Ember integration i've seen is by TOMASZ and can be found here: https://coderwall.com/p/ylogzg
Thing is, that app does not use ember router at all. For sure it won't help you make JQM internal hash pages and Ember router a breeze

Can portions of a site be hosted in another domain?

If a client has a Wordpress site on domain A and I want to integrate some pages for them that are coming from a Rails application that I deploy on domain B is there a way to do that so that all pages appear to be coming from domain A? Are IFrames a reasonable way to do this? I'm trying to add functionality for them without disrupting the existing Wordpress install.
You can use iframes of course. If it's considered reasonable depends on what you are trying to do. I personally try to avoid them.
This one is quite old but still valid: http://www.html-faq.com/htmlframes/?framesareevil

Resources