How to install Rails 3 master from GitHub - ruby-on-rails

I'm using rvm (Ruby Version Manager) and running Rails 3 RC. I need to test an app to see if a bug has been resolved with a recent commit to Rails 3 master on GitHub.
How do I install Rails 3 master from GitHub and then generate a new app?
I can't use
gem install rails --pre
because I want the edge version, not the release candidate.
Can you suggest a helpful gist or blog post?
All I could find was this:
http://weblog.rubyonrails.org/2010/1/1/getting-a-new-app-running-on-edge
and it is out-of-date.
Thanks!

You can create an empty folder, then put a Gemfile inside, with this:
source 'http://rubygems.org'
gem 'rails', :git => 'git://github.com/rails/rails.git'
Then inside the folder, run:
bundle install
Inside the folder again, run:
bundle exec rails new /path/to_my_new_application/appname
And that's it.

You can do this with your rails 3 app Gemfile. Bundler is able to install directly from github and if you dont specify a branch or tag then it will use master. Add this to your Gemfile after you generate your rails 3 app, and then run bundle install and start up your app. After you bundle install it will show you the commit number in Gemfile.lock.. it should be the latest commit number from the master rails repo. Here is what I do in my Gemfile:
gem 'rails', :git => 'git://github.com/rails/rails.git'
#gem 'rails', '3.0.0.rc'
I just uncomment and comment these 2 lines to switch b/w RC and master... and bundle install.
Alternately, you can clone the repo and then use your local source in the Gemfile:
I think it should look something like this (untested):
gem 'rails', :require => 'rails', :path => "/path_to/rails"

Why not take a look through the commit log here: http://github.com/rails/rails/commits/master before cloning the repository? I don't know what bug you are looking for but remember, you can also look at the "diffs" from each commit to see what has changed.

Related

Contributing to Gem - gem not updating

I'm trying to add a small bug fix to an open source gem. Here's what I've done:
cloned the repository to local
made changes and saved
changed gemfile of rails project to point to local version of gem
> gem 'gem_name', path: "/Users/admin/gem_name"
> bundle install
> bundle update gem_name
> rails s
The gem doesn't reflect any changes I've made (gem isn't updated). I had to change the version.rb file and then run bundle update gem_name to see changes. But to my understanding, this shouldn't be required to see changes?
Why don't you fork the gem in github? fix what you want and then point that for your github link... If you think your fix could be great for another users, why not a pull request? ;)
gem 'gem_name', :git => 'https://github.com/my_user/gem.git'

How to make edits to a gem and have that take affect on heroku?

I have a gem to which I want to make a few edits.
I have opened the gem using
bundle open gem_name
Made the edits and they work fine on development.
What do I need to do in order to make the changes take affect on heroku.
There is nothing to commit locally.
Your local gem is modified, but during deployment the one on github gets installed.
What you could do is to find the gem project on github, and fork it.
Then you can apply all your custom mods and commit into your gem repo.
Once you're done, remember to point to the right repo in your Gemfile:
gem your_gem, , :git => "https://github.com/your_user_name/your_gem.git"
You can vendorize the gem like this:-
gem unpack my_private_gem --target vendor/gems
and then in your Gemfile
gem 'my_private_gem', :path => "vendor/gems/my_private_gem-VERSION"

Gemfile gem installation and gemspec dependencies

I have an app whose Gemfile requires a gem that is also dependent on another gem that is currently found on github.
So
app/Gemfile reads
gem "my-gem", :git => "git://github.com/MyCompany/my-gem.git"
my-gem/Gemfile reads
gem "my-gem-2", :git => "git#github.com:MyCompany/my-gem-2.git"
my-gem/my-gem.gemspec reads
spec.add_dependency "my-gem-2"
When I run bundle inside of app I get an error that it can't find gem my-gem-2 which is required by my-gem; however, if I put the following line
gem "my-gem-2", :git => "git#github.com:MyCompany/my-gem-2.git"
inside of app/Gemfile then it works fine.
This practice seems redundant as I wouldn't think I'd have to add gem dependencies of another gem into my parent app. Is there something I'm doing wrong here that myapp can't find my-gem-2?
This is just the way it goes - Gemfile dependencies within gems are just for when you're developing that gem. Only the gemspec gets evaluated when the gem is used elsewhere (and gemspecs have no concept of git dependencies), hence only dependencies in the gemspec apply.
So: you will need to have both git references within your app's Gemfile.
As stated in the gem specification, the list of gems that you provide through add_dependency will be use to make sure those are already installed in the system during the installation process (i.e gem install). So this line:
my-gem/my-gem.gemspec reads spec.add_dependency "my-gem-2"
Will trigger the verification of whether or not the gem is installed in the system, but it will not trigger any automatic installation of such gem, as Bundler would do.
This other line (inside of your gem):
gem "my-gem-2", :git => "git#github.com:MyCompany/my-gem-2.git"
Specify that a gem should come from a git repository with a .gemspec at its root.
For more details: Gems from git repositories

Branch of a Gem is not installed correctly with Rails and Gemfile

Initial Problem
I was using yaml_db in a Rails project, but it seems the default branch has some issues with boolean records. Now I know that there's a branch on github that has a fixed version.
I changed my Gemfile so that this branch will be installed instead of the default yaml_db,
gem 'yaml_db', :git => "https://github.com/robsharp/yaml_db.git"
I run bundle install and it shows:
Using yaml_db (0.2.0) from https://github.com/robsharp/yaml_db.git (at master).
Your bundle is complete! It was installed into /Users/user/.rvm/gems/ruby-1.9.2-p0
Fine. Now the fixed file in the Git repository should have this line in lib/serialization_helper.rb:
record[column] = convert_boolean(record[column])
Yet, when I look at my local file, which is .rvm/gems/ruby-1.9.2-p0/bundler/gems/yaml_db-ca178cfb59cf/lib/serialization_helper.rb, it still shows the unpatched old line:
record[column] = (record[column] == 't' or record[column] == '1')
Fine, seems as my local file isn't changed.
Gem not being installed correctly
Running gem list won't show me yaml_db at all. I removed the Gem lockfile and installed the bundle again, still there is no yaml_db in my Gem listing. Running gem install yaml_db of course only installs the broken version.
Manual Install
I now try to manually install from the Git source.
git clone https://github.com/robsharp/yaml_db.git
cd yaml_db
git checkout -b fix_boolean_checks_to_support_oracle
Still, the serialization_helper.rb file is not updated correctly. I just manually changed it and built the Gem. Everything works fine now.
My new question: Why won't it check out the correct file?
If you run gem list yaml_db and see multiple versions in parenthesis, define the version you need in your Gemfile like so
gem 'yaml_db', '~> 0.2.0', :git => "https://github.com/robsharp/yaml_db.git"
I had a similar problem and found out that the Gemfile.lock file stored my old and not–updated version and used that for my project.

How can I specify a local gem in my Gemfile?

I'd like Bundler to load a local gem. Is there an option for that? Or do I have to move the gem folder into the .bundle directory?
I believe you can do this:
gem "foo", path: "/path/to/foo"
In addition to specifying the path (as Jimmy mentioned) you can also force Bundler to use a local gem for your environment only by using the following configuration option:
$ bundle config set local.GEM_NAME /path/to/local/git/repository
This is extremely helpful if you're developing two gems or a gem and a rails app side-by-side.
Note though, that this only works when you're already using git for your dependency, for example:
# In Gemfile
gem 'rack', :github => 'rack/rack', :branch => 'master'
# In your terminal
$ bundle config set local.rack ~/Work/git/rack
As seen on the docs.
You can also reference a local gem with git if you happen to be working on it.
gem 'foo',
:git => '/Path/to/local/git/repo',
:branch => 'my-feature-branch'
Then, if it changes I run
bundle exec gem uninstall foo
bundle update foo
But I am not sure everyone needs to run these two steps.
In order to use local gem repository in a Rails project, follow the steps below:
Check if your gem folder is a git repository (the command is executed in the gem folder)
git rev-parse --is-inside-work-tree
Getting repository path (the command is executed in the gem folder)
git rev-parse --show-toplevel
Setting up a local override for the rails application
bundle config local.GEM_NAME /path/to/local/git/repository
where GEM_NAME is the name of your gem and /path/to/local/git/repository is the output of the command in point 2
In your application Gemfile add the following line:
gem 'GEM_NAME', :github => 'GEM_NAME/GEM_NAME', :branch => 'master'
Running bundle install should give something like this:
Using GEM_NAME (0.0.1) from git://github.com/GEM_NAME/GEM_NAME.git (at /path/to/local/git/repository)
where GEM_NAME is the name of your gem and /path/to/local/git/repository from point 2
Finally, run bundle list, not gem list and you should see something like this:
GEM_NAME (0.0.1 5a68b88)
where GEM_NAME is the name of your gem
A few important cases I am observing using:
Rails 4.0.2
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux]
Ubuntu 13.10
RubyMine 6.0.3
It seems RubyMine is not showing local gems as an external library. More information about the bug can be found here and here
When I am changing something in the local gem, in order to be loaded in the rails application I should stop/start the rails server
If I am changing the version of the gem, stopping/starting the Rails server gives me an error. In order to fix it, I am specifying the gem version in the rails application Gemfile like this:
gem 'GEM_NAME', '0.0.2', :github => 'GEM_NAME/GEM_NAME', :branch => 'master'
You can reference gems with source:
source: 'https://source.com', git repository (:github => 'git/url')
and with local path
:path => '.../path/gem_name'.
You can learn more about [Gemfiles and how to use them]
(https://kolosek.com/rails-bundle-install-and-gemfile) in this article.
If you want the branch too:
gem 'foo', path: "point/to/your/path", branch: "branch-name"

Resources