I need to detect rack apps and rails 2 apps by simply inspecting the files in a project.
I've been able to do this for rack apps by checking for the existence of a config.ru file. Is there something similar I could check for in a rails 2 app?
From Phusion Passeger documentation: Phusion Passenger checks whether the virtual host is a Rails application by checking whether the following file exists:
dirname(DocumentRoot) + "/config/environment.rb"
This file exists also for rails 3 projects if that is a problem :/.
In config/environment.rb you can look for RAILS_GEM_VERSION = '2.x.x'
In Gemfile.lock for rails (2.x.x)
In Gemfile for gem 'rails', '2.x.x'
The file config/environment.rb should have a statement which mentions the required version of rails, e.g.:
# Specifies gem version of Rails to use when vendor/rails is not present
RAILS_GEM_VERSION = '2.3.5' unless defined? RAILS_GEM_VERSION
Related
I am looking for an efficient a programatic way to retrieve the Ruby version specified in a Rails app Gemfile.
# Gemfile
ruby '2.3.4'
You can use Gem.ruby_version
Gem.ruby_version.to_s
=> "2.2.5.319"
I'm writing my first Rails app. The app uses a lot of enumerations, so I'd like to include this gem that makes it easier to work with them.
I'm stumped by the installation instructions, though, which say
[...] For a rails application configure the gem in the config block of
the config/environment.rb file
config.gem "enumerated_attribute"
In my config/environment.rb I don't see anything that looks like a "config block".
config/environment.rb:
# Load the rails application
require File.expand_path('../application', __FILE__)
# Initialize the rails application
Webtet::Application.initialize!
So what does the author mean when he writes "configure the gem in the config block"?
Does he just want me to include this line in config/environment.rb
config.gem "enumerated_attribute"
?
Looks like this setup instruction was written for rails 2 application. If this gem works with rails 3 you just should add gem 'enumerated_attribute' to your Gemfile. Also you can try to use https://github.com/brainspec/enumerize gem (it works with rails 3 and has SimpleForm, Formtastic support and other awesome features)
I have strange old buggy project on Rails 2.
It have gem's dependencies in config/environment.rb like
config.gem "andand"
config.gem "json"
config.gem "chronic"
config.gem "mini_fb"
all those gems are located in vendor/gems/
andand-1.3.3/
chronic-0.6.7/
json-1.7.3/
mini_fb-1.1.7/
rbet-1.0.3/
redis-3.0.1/
responsys_client-0.0.1/
but when i start unicorn server with this app it always complain that it can't find this gems. Why?
UPDATE
After building and installing gem from vendor/gems rails still complain about it.
I have tweake mini_fb gem into custom mini_fb_custom gem. Changed all references in gemspec and other files from mini_fb to mini_fb_my, installed it and it is shown in gem list as mini_fb_my. But it fails to load from config/environment.rb and complains that
Missing these required gems:
mini_fb_my >= 0
maybe i should rename lib/mini_fb.rb to lib/mini_fb_my.rb
i'll check it.
UPDATE 2
Yes, renaming files rocks!
You still need to install them from those folders, or unicorn will not know where to look for them.
Just install the gems from that directory and unicorn should pick them up.
UPDATE
You can install your gems locally with this command
gem install --local vendor/gems/gem/gem-name.gem
On more recent versions of rails you just specify path on the Gemfile
gem "gem-name", path: "path/to/gem"
My advice: replace the obsolete gem configuration with bundler (it works fine with rails 2, there should be a tutorial for rails 2 available on their website).
Configuration through gem command, freezing gems, etc. is just pain in the a** and it seemed kinda buggy to me when I'd used it (long time ago).
I have a library that I'm trying to get working with rails 3 (specifically feedzirra) which I can require ok in irb but it breaks the console in my app with the following error:
http://pastie.org/855976
Found a bit of info on using feedzirra with rails 3. It looks like your problem might be with the Loofah library feedzira uses. It uses the deprecated config.framework.
Here's a link with some more info http://www.mythoughtpot.com/2010/02/10/feedzirra-on-rails3/
Rails3 modifies the $LOAD_PATH so it only contains gems listed in the Gemfile.
($LOAD_PATH is an array of directories where Ruby searches for libraries).
So you must add the Gem to the Gemfile and run bundle install.
You can check if the gem is in your path by typing puts $LOAD_PATH.grep(/feedzirra/) in the rails console.
For more information on using Bundler in Rails3 check out these:
http://railsdispatch.com/posts/bundler
http://railscasts.com/episodes/201-bundler
Why does this happen?
ruby script/console
Loading development environment (Rails 2.0.2)
>> exit
jay-z-mac-pro:justinz$ rails -v
Rails 2.3.3
Look at your RAILS_ROOT/config/environment.rb file. In it you can set and lock the Rails gem version to load. Look for the line:
RAILS_GEM_VERSION = '2.0.2' unless defined? RAILS_GEM_VERSION
Change that to
RAILS_GEM_VERSION = '2.3.3' unless defined? RAILS_GEM_VERSION
Maybe your project is pinned to version 2.0.2. I haven't worked with Rails for quite some time, so I can't say for sure, but I believe this can be done in a config file.
Also, you should check if Rails is in your vendor directory (was that what it is called?). That's another way to force a specific version.
Check your config/environment.rb, it sets the Rails version for your application. It should be something like this:
RAILS_GEM_VERSION = '2.3.5' unless defined? RAILS_GEM_VERSION
script/console will load your application with the gems (including Rails) that you define in the config. rails is just the latest rails gem installed.
However, moving from Rails 2.0.2 to 2.3.3 is a pretty big change, you'll want to be careful about upgrading. Make sure to read the docs as it relates to your application.