RefineryCMS for RESTful API - ruby-on-rails

I need to build a site with a CMS interface and RESTful api (to use with a clientside framework, angularJS). Would RefineryCMS work for me?
Also, does anyone have experience with Refinery, LocomotiveCMS, or any other rails-based CMSs? Do you prefer one over the other? Why?
Thanks!

What do you mean by CMS interface? Like you need to allow users to create Pages, embed images/files, etc?
I use Refinery alot, and really like it. However, it has no built in support for a RESTful api like you want, I'm assuming you mean via JSON or something. To do this you'd have to override the refinerycms-core engine and it's crud.rb file. This is where Refinery defines all the REST actions dynamically. I'm sure you'd have to also override other engines depending on which functionality of the core engines you're using. I'd probably try doing a proof of concept first, then on seeing how smoothly that goes, decide to continue or try another CMS framework.
Another lightweight alternative to Refinery is Comfortable Mexican Sofa. It was pretty easy to add on to a full Rails app I maintain to provide CMS functionality. Though I didn't have to override any internal parts of it. I've never used LocomotiveCMS. You could also role your own CMS and use something like ActiveAdmin for the backend.

Related

What would be the best way to use AngularJS with Ruby on Rails?

I'm about to start a new project and I am unsure if using AngularJS for my front end would be a good idea not. I've read about people saying this isn't the smartest way of doing a project. And even if I did, Is there a way to get AngularJS to interact with the controllers? This question may be redundant but I am actually curious of how to effectively do this without it being a waste of time.
I've never completely done it, but I believe the way to go is to build a Rails api and then have a separate Angular project use said api. The api could also be used to build a mobile app. I think the Angular project would still need to be served from a Node.js server in production, but I don't think that would be a big deal.
This is what I used to learn how to build a Rails api: http://apionrails.icalialabs.com/book/chapter_one
You can do it within an existing project and share the models from it.
There are several different approaches to accomplish that. I tried about 5 different guides out there, the best I found (and I finally sticked to) was https://thinkster.io/angular-rails - This guide should help you build a basic CRUD app with angular connected to rails.
You use Rails as an JSON RESTful API which responds to Ajax-Requests (Get, Post, Put, Delete). Angular will handle the frontend stuff - sending those Ajax requests to the routes/methods defined in your rails controllers. So yes, of course your AngularJS app can interact with your rails controllers.
This also helped me to understand the setup in the beginning: Instead of the Rails View, you will be using AngularJS as your view:
I really love using angular with rails, because setting up the JSON responses (especially with Active Model Serializer Gem) is very easy and quickly done. i deffinitely can recommend it, and I have not encountered any unsolvable problems - so far.
Just go trough this guide I linked and you will see if this setup fits your needs.
The short answer is that your Rails application will have to present some kind of a public API for your AngularJS application to consume. Angular (and it's brethren, like React and Ember) runs client-side, on the browser, and it needs "something" to make AJAX calls against. That "something", i.e. your backend, can be Firebase, Parse, AWS Lambdas, Rails API, etc. Since you already have a Rails application, it probably makes the most sense to add some RESTful API endpoints that use the existing models (and possibly controllers) to consume/produce JSON payloads from/for the client.

What's the benefit of using Sinatra instead of RoR if I'm only need a DB and an API

I need to build a web service, for a mobile game, to manage the states of multiplayer games. I need a database and an RESTful API to access it. I'm very familiar with Ruby On Rails and was thinking of using that since I can throw together the DB and API pretty quickly. However, since RoR is a framework for building web pages and I'm not actually building any web pages, it naturally seems like the wrong technology to use even though it would work. As such, I'm considering using Ruby on Sinatra, but I've never used it before and I'll have to kill some time learning it. For you Ruby gurus, is there an advantage to using Sinatra or a disadvantage to using RoR for what I'm trying to accomplish?
Thanks so much in advance for your wisdom!
You know Rails, you don't know Sinatra. Personally I prefer the latter for things like building APIs, but there's nothing stopping you from doing it in Rails, and there's nothing intrinsically wrong with it either. Unless you want to see this as a learning opportunity for getting into Sinatra, I'd say stick with Rails. Here's some links that might be useful btw:
Building APIs With Rails
Building a Platform API on Rails
It probably depends on your API. If you need more than just a bunch of routes then you will have to come up with your own solutions (authentication, ...).
If all you need is some RESTfulness without the added weight, Sinatra is great. All you need to know is what happens in what route and you're fine. See the Sinatra Readme which has all the information to get started.

What tech stack/platform to use for a project?

This is a bit of a weird meta-programming question, but I've realized that my new project doesn't need a full MVC framework, and being a rails guy, I'm not sure what to use now.
To give you a gist of the necessary functionality; this website will display static pages, but users will be able to log in and 'edit their current plans'. All purchasing and credit card editing is being handled by a recurring payment subscriber, I just need a page to edit their current plan. All of that will be done through (dynamic) XML API calls, so no database is necessary.
Should I stick with my typical rails/nginx stack, or is there something I could use that would lighten the load, since I don't need the Rails heft. I'm familiar with python and PHP but would prefer not to go that route. Is Sinatra a good choice here?
tl;dr: What's a good way to quickly serve mostly static pages, preferably in Ruby, with some pages requiring dynamic XML rendering?
If you want to stick with Ruby, Sinatra would be fine, as would Rails Metal.
If you're feeling a bit adventurous and want to get some useful experience with the technology that rails uses you could try building a Rack application. It's a pretty simple API to be able to respond to generic HTTP queries, and from there you can quickly build static file handling and XML processing. It's also considerably faster to start up and serve pages than rails.
http://github.com/cloudhead/toto is an example of a decent Rack based application.
If you know Rails, then why not just stick with it? That way you can use all authentication features, etc. that you're used to without having to learn another platform and incur the implementation risks that that includes. If the application ever grows beyond what's expected you're already on a solid base.

how does cairngorm+flex integrate with rails?

I mean, the mvc for cairngorm and the one in rails don't overlap their functionalities? I'm not sure I understand the need for cairngorm with the rails backend..
There is no need, it's an option, Cairgorm see's the whole Rails as a model. Rails send xml instead of html so no browser-css-details headaches.
You can use rails as a REST layer and put your business logic in flex.
You can use cairgorm as a candy cover over a complex but well tested rails application.
You can find middle of the way solution that suits to you.
We do implement most business logic in rails but use flex/cairgorm to show each user only the right buttons/forms/controls to her task, and to do it in a nice browser-independent way.
Hope this helps you, feel free to ask any detail
Rails is MVC for the server. You still need an architecture for a sufficiently complex client application. We're using PureMVC on the client with a REST (JSON) interface to a Rails server and it's working nicely. PureMVC allows for the client's model to be independent from the client's view components, and makes it easy to update independent view components simultaneously.

Simplest way to allow posting to a Rails site using MarsEdit/Ecto/etc?

I have a simple site, using restful_authentication and a simple model for the posts. I would like to use MarsEdit (or something like Ecto) to post/edit content. How would I go about this?
The XML-RPC system is rather bewildering - there's a lot of different variations (Atom, MovableType, metaWeblog, Blogger, TypePad, probably others), never mind actually implementing any of them.. The Action Web Service API in Rails, which is intended to implement such APIs, has deprecated a while ago..
Try a plugin...
http://github.com/calavera/atompub-server/tree/master
Or this library...
http://github.com/inkspot/alumina/tree/master
As a starter/prototype for what you need

Resources