How to generate ActiveResource specific template files - ruby-on-rails

We are planning to supporting a ruby 1.9.x application (which has database connectivity via ActiveRecord, but no user interface). We used rails (3.1.3) generate command to generate the application template files, but we wouldn't need access to view specific files. What command should I use to generate only the files which would be needed REST services which will be exposed via an ActiveResource

I think this answer sheds some light on it:
Using ActiveResource without Rails
And this article seems to describe a project that exposes a RESTful API, without an interface http://www.therailsway.com/2007/9/3/using-activeresource-to-consume-web-services/
You could also just straight up delete the view files, and in your controllers, avoid rendering any of the templates. Rails will, by default, will try to find a template with a name matching the action, but you can tell your actions not to render anything.
The other option is to not write it as a web app, but instead as a Rack app, or just pure Ruby, if you don't need an interface. Rails is really built to create interactive web apps, so maybe everything that comes with Rails by default is really more than you need?

Related

Can a Rails application template include generator parameters?

When I start a new Rails application, I often use certain parameters to rails new like --skip-spring or --skip-turbolinks.
I understand I can put these in ~/.railsrc, but when using multiple dev computers, it can be a bit tedious to keep railsrc files in sync across all of them.
Can I use application templates to add these parameters to the generator? That would be great, because application templates can be referenced by a url and downloaded on the fly.
(Also I know I can use templates to make changes after the application is created, so I can remove spring or turbolinks or whatever, but it would be much nicer to never generate the app that way.)
To answer my own question after looking into how this works, I think the short answer is that it's not possible to add generator parameters from an application template to rails new itself. The reason is that the template code only runs when the application is already generated.

Is there a Rails equivalent of Sinatra's 'register'?

I'm in the process of creating a rubygem which will be used with both Sinatra and Rails applications. Ideally, I'd like to have a single gem which can work with both frameworks. It's very simple - it provides some helpers, styles, scripts and view partials.
For Sinatra, I use the register method to register the module, which in turn adds the helpers, adds some entries to the load paths and optionally creates some actions/routes. So far so good.
My question is: What is the rails equivalent of this? Engines?
Since you need to define routes, I think a rails engine would work best.
You can load helpers with railties too, but I don't think it's possible to define routes with railties.
Rails Engines:
http://edgeguides.rubyonrails.org/engines.html
Railties:
http://edgeapi.rubyonrails.org/classes/Rails/Railtie.html

General advice and recommended folder structure - Sinatra

How would you structure a simple Sinatra app?
I'm making it right now and I want the app to have these features:
The "app" is more of an admin dashboard for all the information inside it. Then another app will access the information via REST. I have not created the dashboard yet, just the getting of things from the database
Sessions and authentication (have not implemented this yet)
You can upload pictures, and other the other app can display those pictures
I have created a testing file using RSpec
Reports generation via Prawn
Currently the setup is just this:
app.rb
test_app.rb
because I have literally just the app and testing file. So far I have used Datamapper for the ORM, SQLite for the database. This is my first Ruby/Sinatra project, so any and all advice is welcome - what other libraries should I be using, should I put stuff like config.ru, etc.
Sinatra is not opinionated when it comes to your file structure, you can place files however you like. When I first started I just dropped everything in the top level, but over time reading how people structure their code, reading over the source code of gems I've broken up my code into smaller .rb files that fulfill a specific function and places all of them under /lib, it's a convention carried over from rails perhaps but does not have any of the magic associated with it in rails. If you use scss or coffee script they depend on certain folders to exist, you will discover for yourself over time (and even then you can reconfigure them however you wish) and from this you will figure out what works best for you.
if you write a restful api, check out grape - https://github.com/intridea/grape
you will also find sinatra-contrib to be very useful - https://github.com/sinatra/sinatra-contrib
As for what to do with your config.ru - https://github.com/rack/rack/wiki/%28tutorial%29-rackup-howto

Locomotive CMS with Rails - location for liquid templates

I'm new to both Ruby on Rails and Locomotive CMS, but I'm just starting to create my first site with them.
I've got the engine running in a full Rails app (I'm going to need to deploy it on our own server later on). But it's just spitting out the 'Template' content defined through the admin interface, without any other template/content around it.
I can 'fix' it by shoving the html for the whole page in through this input field. But that's not right, surely? The Getting Started guide talks of putting the templates in the filesystem, at something like: Pages/index/first page. "All pages are inherited from index". I have an index.liquid under views/pages but it's not picking that up... (I've tried a couple of other locations too).
I'm sure this is a dumb question, but please could someone tell me where to put my template in the file system? Or how to point Locomotive to pick it up from the right place?
(I did get the file system liquid template working by defining it through the Rails way, with a route, a controller and adding a liquid template initializer I found here. But then it's missing the variables that should come from the CMS content).
I'm loading the site using bundle exec unicorn_rails. And I'm using Rails v3.2.13, Ruby v1.9.3 and Locomotive_cms v2.2.2.
Thanks!
I'm Didier from LocomotiveCMS.
LocomotiveCMS is a little bit different from the other CMS, in a sense, we offer a tool named Wagon to manage your site locally without having to install mongodb, rails and some other components.
Another huge benefit is that you can write your templates in HAML and your CSS in SASS/ SCSS or Less (we embedded Compass as well) and with our preferred texts editor (editing a whole site in a browser is a nightmare).
That's a nice eco-system in order to be super efficient when it comes to develop a LocomotiveCMS site.
Once you're done with your local work, you can deploy your site to a remote LocomotiveCMS engine in a similar way you push your application to Heroku. Actually, pushing a site will create the back-office for the final end user.
I suggest you to read that page.
http://doc.locomotivecms.com/guides/get-started/requirements
and this one too
http://www.locomotivecms.com/tour
Our message is still not clear on our official website but believe me, we are working to make it better.
Hope it will help you !
Didier

Ruby On Rails CMS Framework

I want to create a framework for rails application. It will be a rails application but packed into gem (like a Radiant CMS).
It must work like this:
gem install cmsframework
and then:
cmsframework the_app
After that we have a skeleton framework for a rails app, without any controllers, etc. All controllers are loaded from cmsframework gem.
If I want to rewrite some files (for example public/styles.css), I must simply create it in my app (the_app).
If I want new functions in my app I can create a plugin. But the main functionalities must be loaded from cmsframework gem.
What is the best way to implement this?
Maybe start here: http://guides.rails.info/plugins.html. Pay close attention to the parts about adding custom generators and packaging as a gem. This may help as well: http://railscasts.com/episodes/218-making-generators-in-rails-3.
You can use this framework it is very good CamaleonCMS

Resources