How do I change the default gemfile created with 'rails new' command? - ruby-on-rails-3.1

I have recently experienced an issue where I must add the following to my gemfile:
gem 'execjs'
gem 'therubyracer'
I must do this to avoid a javascript runtime error that occurs when starting the rails server. I would like to have this modification added to all new gemfiles created with the rails new command.

You're looking for application templates.

Rails documentation on Application Templates
If you want the option to customize each app individually instead of having a rigid template, a really good option is Rails Composer. It prompts you about common gems during setup, and it nails a lot of the more common gems.
Finally, if you like Rails Composer, but want to be able to re-use application templates, check out Rails Apps Composer. I haven't looked into this too much, but it seems to give you a lot of flexibility while doing most of the heavy lifting for you.

Related

Bundler: Allow user added gems in an UserGemfile

I'm developing a ruby/rails application which should be highly extensible by adding plugins. A plugin is - obviously - a gem, which follows specific roules and contains library code, a rails engine with assets, routes, controllers, views and whatever. Additionally there wille be some kind of API which allows the plugin developer to register custom entries to abstract concepts of the app like adding cronjobs (theres some kind of cron in the main system), adding commands to the CLI and so on.
There will be some 'builtin' plugins containted in the Gemfile shipped with the app due they're part of the app and always activated. And there will be a pool of community written gems which are optional.
Now I'm searching for a possibility to let the user, who installs the app on his machine, addional gems (containing plugins) to the app.
The simplest (but not best) solution would be to say "Just add the plugin gems you want to the Gemfile before running bundle install)". But if there comes an update of the app, the Gemfile would be potentially conflicting and either be resetted or the user have to resolve those conflicts. That's something I don't want actually.
A nicer way would be to say "Hey, here's a UserGemfile, just add the plugin gems you want to that file and run bundle install". That UserGemfile would be listed in the .gitignore and everything would be nice.
Unfortunately it seems like bundler doesn't support something like that.
Do you have any advice how to tackle that issue?
You can do something like this, in, say, import_gems:
puts `cat Gemfile UserGemfile > EffectiveGemfile`
puts `bundle install --gemfile=EffectiveGemfile`
Then, when you run your application, specify the Gemfile:
BUNDLE_GEMFILE=EffectiveGemfile bundle list
Make sure to add EffectiveGemfile and EffectiveGemfile.lock to .gitignore as well.

How do I create a config.ru file and a Rakefile?

I know you create a Gemfile from the command line by typing "bundle init." But how do you create config.ru file and a Rakefile?
Kristine, the real question is not how, but rather why would you want to create them.
Those three files serve three different purposes, and none are required for a Ruby application to get started:
Gemfile (and its companion Gemfile.lock that gets generated by the first bundle install and should be kept as safely as the other one) – this is one you meet most often.
It belongs and is used by a tool called Bundler. It's a dependency management tool. When your application needs some other library called "gem", you can list it in your Gemfile, do bundle install and later on when you run your application like bundle exec ruby yourapp.rb Bundler will take care of the environment in such a way, that your application always gets the same versions of gems that you have designed it to get (those versions are actually stored in Gemfile.lock file, you can peek there).
You can easily do without Bundler, but it usually makes sense to stick to certain gem versions. That's why people usually use it. I would highly suggest you taking a look at the tool's site.
config.ru – this is very common for web applications. It's a Rack configuration file. There's a widely spread in Ruby world web server API called Rack. It enables decoupling web applications (like your Rails app, or Sinatra app) from the underlying web application server (like Thin, Unicorn or WEBrick).
Though you can certainly create this on your own, you most certainly don't need to. It's been a long way in my Ruby/Rails experience before I had to actually do this. Usually this file gets bootstrapped when you create a new Rails app by calling rails new.
And vanilla command line Ruby apps just don't need it.
Rakefile – this is, again, a pretty wide-spread beast. What Makefile is for make, Rakefile is for rake. Rake is a Ruby tool to describe and invoke certain tasks from a command line. For example, when you do bundle exec rake db:migrate, you actually start a task described by a Rakefile.
You can easily design your own tasks, but as you start using Rails you usually don't need to. rails new drops a Rakefile for you that's just enough to start with, and unless you're doing some really custom (that should, exempli gratia, involve calling your Rails app code from the command line), there's no necessity in fiddling with it.
Needless to say, if you're doing some simple Ruby console app that just asks your name and greets you, you don't need this file either.
Hope this helps you getting your head around this and smooths your ride into the Rails world!

Salesforce Gem for Rails 3.1

I have this rails Application which uses salesforce App. I want to know if there are any gem and tutorials to build Salesforce App in rails easily. I found this rforcedotcom gem but it lacks tutorial for Rails 3.
The current standard gem is the databasedotcom gem, which is updated fairly actively and officially endorsed by Salesforce.
There is also the asf-rest-adapter gem (which has a dependency on asf-soap-adapter) by Ray Gao which I have running in a number of apps, and works quite well.
There's yet another gem out now called Restforce.
The author bills it as "lighter weight" with "greater flexibility and more advanced functionality" than the databasedotcom gem (and he should know -- he worked on the that gem too).
Another alternative is to use Active Force that uses RestForce as a backend and provides an ActiveRecord like interface. It also have some generators to get up and running faster.

How can I help TextMate recognize which bundle to load?

I have a problem with four bundles I'm using, specifically Ruby, Ruby on Rails, RSpec and Sinatra.
Most of the time TextMate manages to get the bundle type right, but for these, I find myself constantly switching form Sinatra to Ruby on Rails, as some model files get recognized as Sinatra.
It also happens a lot with RSpec, where the Sinatra bundle sometimes takes precedence.
Is there any way to manage the way in which bundles are recognized? It would be great if I could somehow hint TextMate what bundles to completely ignore in a specific project, or based on a directory structure.
I think you can modify your Sinatra bundle to trigger as soon as it detects require 'sinatra'

i18n assets management / translation UI

i'm building a multi-lingual webapp with i18n from the ground up, and while i myself can deal with an army of yml files, the languages i speak are ( very ) limited, and would eventually like to ask for outside help.
I'd like to know if anyone here is using a UI plugin/gem ( not unlike django-rosetta on django ) to deal with multiple translators, some of them unwilling or unable to mess with 100+ files in a repository, working on language data.
thanks &regards,
Andras
( apologies if you bumped into this on rubyonrails-talk already )
There is a rails3 branch of the tolk gem on github. You can install it by inserting the following line in your Gemfile
gem "tolk", :git => "http://github.com/dhh/tolk.git", :branch => "rails3"
We used the translate gem for one of our projects before and it worked nicely. It's not perfect as your YAML files are no longer in your SCM but it lets the client translate his own application. We only used one YAML file per language so I don't know if it scales to a few 100 files...
DHH created another one, tolk, but I didn't have a chance to look at it yet.
Both solutions are for Rails 2.x, haven't tried this in Rails 3 yet.
Although this might be a bit late, the phrase service looks like something that suits your need. They provide i18n management through in-place edit.
For Rails 3, the URL for tolk is just http://github.com/tolk/tolk and installation is as simple as adding
gem "tolk"
to your Gemfile and running bundle install.

Resources