Rails Basics: Where's My Installation, Sources, API, Online Sources - ruby-on-rails

I'm trying to run this method which should work according to this:
ActiveSupport::TimeZone.new("whatever",3600)
but this initializer doesn't exist.
So I would like to look at the sources for my Rails version (2.3.4) to see if it's private or if I'm missing the point completely (the one-argument constructor works).
And suddenly I realize that I have no idea where to find the docs for my version nor the API. I use api.rubyonrails.org constantly (linked from here), but I'm not even sure what version it refers to (2.3.2, the 'current' version?). How can I get the API docs for my installation? How can I view the SOURCE for my Rails version? Can I view it in my Rails installation (either OSX or Ubuntu)? Online?
If the version were vendored (it's not), how would that affect my question?

Check out http://github.com/makandra/aegis/tree/master for a local gem documentation server. Even simpler is the gem server command. Both give documentation for installed versions of gems.
Also, sometimes gem install skips generating RDoc documentation; use gem rdoc --all to create docs for all installed gems. The docs are saved to /your-ruby-path/lib/ruby/gems/1.8/docs, by the way.
The source for all gems is at /your-ruby-path/lib/ruby/gems/1.8/gems, that includes both Rails and ActiveSupport, which are actually two separate gems.

There are several ways to get at your docs, the easiest being with a frozen rails gem. If you don't want to freeze it for some reason you can create a dummy rails app, freeze rails, and gen the docs:
rails dummy_app
rake rails:freeze:gems
rake doc:rails
rake rails:unfreeze
You can also generate docs for plugins you have installed. Try rake -T doc.
Freezing your rails gem has the added benefit that the code is right there for you to browse, but you can always go to wherever your gems get installed on your system. On MacOS this could be either ~/.gems, /Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems, or maybe other?

Related

Resolving gem version incompatibility

I am new to Ruby, Rails and gem management. One thing what I have noticed is that whenever I run bundle install (even within the project directory) it seems to install gems which affects other gem based Rails projects too.
For instance, assume that after running bundle install within one gem based Rail project (which installs a bunch of gems from the gemfile) I run into gem incompatibility issues. Now, these issues will manifest in all the other gem based projects too and will present themselves everytime I attempt to rackup
My questions are:
1) Is there a way to localize this damage (gem version incompatibility) to the current project and not have other projects affected?
2) Is there a good way to obtain a compatible set of gems or is the only way to look at the gem dependencies on a gem-by-gem basis (look at the tree) and figure out the compatible ones? I seem to be wasting a lot of time on this and if I fix one something else seems to break.
Please let me know what I'm missing here or point me to resources.
Thanks
It sounds like you're missing use of bundle exec
Description
This command executes the command, making all gems specified in the Gemfile(5) available to require in Ruby programs.
Essentially, if you would normally have run something like rspec spec/my_spec.rb, and you want to use the gems specified in the Gemfile(5) and installed via bundle install(1), you should run bundle exec rspec spec/my_spec.rb.
bundle install will install gems to $GEM_HOME which is shared by any apps using the same ruby and can result in multiple versions of the same gem being installed (this is expected and normal). If you don't then also use bundle exec to load only the gem versions specified in your Gemfile you can get incompatibility errors or unexpected behavior as ruby doesn't know which version of a particular gem to require.
RVM, rbenv, and other ruby version managers are useful tools for both isolating gems per project (which isn't really necessary when also using bundler) and for allowing multiple ruby versions to be installed on the same machine (which is not handled by bundler and can be very useful when developing multiple apps with different ruby version requirements).

When I download a Rails open source project, how can I know which version of Rails or gems is needed?

When I download an open source Rails project, how can I know which version of Rails or gems is needed?
For example, I want to build a blog. Then I do this:
~$ git clone git://github.com/mojombo/jekyll.git
That is a free open blog project. When the clone is 100% done.
~$ cd jekyll
~$ rake db:create
rake/rdoctask is deprecated. Use rdoc/task instead (in RDoc 2.4.2+)
rake aborted!
Don't know how to build task 'db:create'
So what's wrong in my Rails or Gem or any other? Is there a problem of version?
Jekyll is not a Rails project. There is no db:create Rake task.
I'd suggest taking a look # the documentation to figure out how to use it.
Jekyll is not a rails app, however...
I would always start with the project's Gemfile (if they are using bundler), if the developer has specified versions for the gems, this should give you a good look at the specific version requirements.
As Brian and Nate have said, read the documentation about it.
I personally have a Jekyll-powered site that you could use as an example if you're stuck. The documentation contains pretty good examples as well.
But to get you started: Jekyll doesn't really have any database backing to it. You must create the directory structure--as outlined in the Usage guide--yourself.
For generating new posts, I have a script called new.rb in my repository. Simply because I can't be bothered remembering what the Wordpress ID was for the previous post (I imported from Wordpress).
Once you've got a post written, install the jekyll gem:
gem install jekyll
Then run jekyll --server. This will parse the post into beautiful HTML which you can view at http://localhost:4000. Once you're satisfied with it, put it online somewhere with Apache or Nginx serving it as it would any other static HTML site.
Finally, if you're ever looking for an alternative, I've heard good things about nanoc.

Managing many Ruby on Rails applications of different versions

I'm learning Ruby on Rails with the AWDR book and have had to be specific about which version of Rails and Ruby that I am running on my local machine. I have just discovered that I need to roll back from ruby 1.8.7 to ruby 1.8.6 here. I also needed to roll back Rails to support the scaffold method so I could start the tutorial easily.
My question is: When I start contracting, developing and deploying projects in the real world, how am I going to manage all these different versions?
It looks to me like Rail's low tolerance for legacy code negates its ease of use philosophy! But I'm sure I'll grow to appreciate RoR.
As for Rails, What you can do is freezing your version, for example:
Make sure to install the proper Rails version, suppose you want version 2.2.2 : gem install rails v=2.2.2
Freeze and pack Rails with the project itself : rake rails:freeze:edge RELEASE=2.2.2
Now you will find Rails packed inside the vendor folder of your project, so you don't have to install Rails on the deploying machine.
And for Ruby, I like Ruby Version Manager(RVM), the easiest way to manage Ruby versions.
RubyGems is Ruby's package manager. You can install as many versions of gems (packages) as you want. You can install the latest by running sudo gem install rails (at the moment it will install 2.3.5). If you need 2.2.2, specify that with the -v or --version option: sudo gem install rails --version 2.2.2. Rails also installs a binary (yes, I know it's not really a binary file), rails, which generates a project. Because you have several versions of the gem, you need to control which binary gets called. When you install the rails gem, RubyGems puts a file in it's bin/ dir, which is a "link" to the real rails binary. That is the one you "call" when you say rails on the command line. However, all of the rubygems "link" binaries accept a parameter of it's own, which is what version you want to use. You would use the 2.2.2 rails binary like this:
rails _2.2.2_ my_project
I think the default is to use the most recent version, so if you want to use the most recent version, do this:
rails myproject
However, I see that you use 2.2.2 to get access to the scaffold method. I would strongly suggest you not to use that method, there's a reason for removing it. The scaffold method hides code, and makes customization hard. Instead, use the scaffold generator:
./script/generate scaffold --help
Good luck on your future rails adventures!
The latest version of Agile Web is written for 2.2.2 I believe. For this basic app they walk you through I'm very certain it should work with 2.3.x
The answer to the question for how you keep up is that you update your apps as needed and read the api and Changleogs to find out what has changed and fix the stuff that upgrades break. A great way to help with this is having a good test suite with good test coverage.

says if i develop a Ruby on Rails application using Rails 2.3.2, will that usually be compatible with Passenger on my hosting company?

says if i develop a Ruby on Rails application using Rails 2.3.2, will that usually be compatible with Passenger on my hosting company?
If i ssh to my hosting company and type rails -v, i get 2.2.2... so looks like they might be using Rails 2.2.2.
So if i develop a Rails app on my Macbook and ftp all files over there, will the Passenger there usually work well with the generated code with the current version of Rails?
Freeze rails into vendor/rails using the built in rake task. That way your app will ue the version of rails you want it to no matter where you deploy it.
rake rails:freeze:gems
And the easiest way to do a specific version I know of.
rake rails:freeze:edge RELEASE=2.3.2.1
Now your version of rails will go with you where you send your app.
You can unpack other gem dependencies into vendor/gems for any gem you are using and want to be sure that it is available where ever you deploy the application.
rake gems:unpack
And to ensure their dependencies go to:
rake gems:unpack:dependencies
I would also suggest that you verify that they are running the latest version of passenger.
I would verify the version of Passenger they have installed (or confirm they have it installed at all). I would also suggest you freeze your version of Rails.
Just second something for railsninja's answer .
First say, it won't work straightaway.
Is that host a vps to you or have sudo access somehow?
If yes, I suggest you to do rake gems:install instead of gems:unpack, because some of gems are os dependent e.g (Rcov, RedCloth...etc.)
I will ask the hosting company of their passenger's configuration, the important question will be if they use RailsSpawnMethod: smart or smart-lv2(default).If they use the smart method, then it is a better idea to freeze your gems and rails otherwise will have the compatible issue as you can find reference from passenger user manual about the RailsSpawnMethod.
It will be nearly 100% compatible if you freeze your gems(all the gems need to be declared correctly in the environment.rb with config.gem, e.g(config.gem 'will_paginate',:source=>"http://gems.github.com")) and RAILS!!!!!

Do I need to revert to an older version of Rails just to run a single legacy app (among other problems)?

I have an older Rails app that I need to run. But I have the latest version of Rails.
When I try to run this older app it says:
Missing the Rails 1.99.0 gem. Please
gem install -v=1.99.0 rails
But when I run the command: gem install -v=1.99.0 rails
ERROR: could not find gem rails
locally or in a repository
Not sure what to do next. Could someone help me understand what's happening here?
And my second question, related to this problem is: It seems silly that I need to revert to an older version of Rails just to run this one legacy app - there must be a better way of doing this?
AFAIK, v1.99.0 is sort of a v2.0 prerelease, so you could try installing v2.0.x, changing the RAILS_GEM_VERSION in config/environment.rb and runing rake rails:update.
If you think about it, it's not as silly as it might seem at first. You make an app using a fast evolving web framework as RoR. Your choices are: continue developing your app at aproximately the same pace the framework is evolving, or freeze the rails gem (and evertything else your app depends on, like gems, plugins) into your app in order to make it less fragile to expecting gem updates.
Regarding the second question: yes it is silly. Fortunately the Rails team spotted that silliness and at some point they gave us the ability to "freeze" the versions of Rails libraries required by an application (and also specific gem versions) into the vendor directory.
To freeze your version of Rails:
rake rails:freeze:gems
There's a good blog post from a while back describing this.
Unless you install and deploy RVM, your installation will roll back your system rails installation, which will impact your other projects. If you want to manually administrate your development environment this way, you can uninstall rails first, and then install the desired version of rails for the current project.
But try to install your rails gem instead with this syntax:
sudo gem install rails -v 1.99.0

Resources