I have a client who has requested for me to build them a website with a very user friendly way to update content. They have expressed familiarity with wordpress, and expressed interest in being able to use the wordpress front-end to update their content.
I had originally intended to build them a simple admin page, where they can create posts, or add other types of content.. but it seems like wordpress has most of the functionality already in place.
The main problem is that i am a RoR developer. I prefer to use haml for every thing I do, and have 100% full control over how the site works.
So i was hoping someone out there would have an idea of a way i could still build the site using rails and haml, but still allow my client to update using wordpress. I thought maybe i could access the wordpress api, and just pull the content and display it the way i want? or maybe i should go with another CMS.. like Refinery?
Honestly, I just really dont want to have to touch PHP, and preferably use haml, rather than html. O_o
This seems to be working for me (I’m loading from WordPress as secondary database, hence the
establish_connection()
calls and overridingtable_name
. This should get most of the way there, giving you access to the WordPress data as ActiveRecord objects. I haven’t yet written the wrapper around Posts (WPPost
) to make them a bit more user friendly from an API perspective, but this should work well for Rails-based display of WordPress data.I then wrap up the category in a simple ruby object that makes accessing the data easy:
Here’s my database.yml (make sure that your db user has read-only access to the wordpress db to avoid any ActiveRecord mishaps):
The Museum of Modern Art had a WordPress JSON API plugin built for this exact purpose: https://github.com/dphiffer/wp-json-api
This allowed them to build a RoR-based front-end layer while maintaining a WordPress-driven back-end layer.
The older answers are not relevant anymore. WordPress now provides a Rest API which can be accessed here:
https://developer.wordpress.org/rest-api/
1) You will probably want to integrate all routing (by taking the “slug” from the articles) in your rails app to serve the articles correctly and present them with a nice “show” view.
2) If you want to store data in the rails system (e.g. for routing and to increase speed) you could create a database table called wp_articles, simply read the full article list or update relevant articles, then present them similar to your normal code.
I’ve looked at the non-maintained MOMA gem (not required anymore, not maintained), checked the above answer with direct database access (huge effort, slower, outdated) and read about a slighlty complex direct javascript based solution here (http://marydickson.com/how-to-use-the-wordpress-rest-api-in-rails/), but I think that simply copying the relevant info into your system and then presenting them with the normal MVC process is the easiest way.
Disadvantages: Some additional WP-Plugins provide more database fields and other information and its not clear whether you can always access those via the API. So you might have slightly limited functionality.
You could install WordPress then reproduce the wordpress database as
Model
s and add the associations like wordpress uses them. Then you would be able to access the data using rails that were entered in the wordpress frontend. I did something like this in the past but not as a permanent solution but as a datasource for migration to another solution. Its possible, its not nice but it works.But one question: Why are you using wordpress for a thing its not mighty enough?! Its a CMS not a framework for challenging tasks. If it doesnt fit the needs of the costumer its simply not the right thing to use. You could rather build a similar GUI using rails then fiddling with wordpress.
Concerning HAML, you can still write your views in haml, and then use
haml input.haml output.html
on the command line. A bit boring, but you don’t have to write html.use MAMP and install wordpress.
open the page in your localhost.
then you can use the firefox tool to see the html code.