Angel \”Java\” Lopez on Blog

October 13, 2013

Exploring Ruby on Rails (1) Install

Filed under: Ruby, Ruby on Rails — ajlopez @ 1:39 pm

I’m playing with Ruby. As a dynamic language, it is one of the programming languages to explore. I like plain Ruby, and write small programs using TDD (see my video in Anglish Playing with Ruby).

Now, I want to explore Ruby on Rails. It’s not in my comfort zone, because I think it is a “big project”, now in version 4.0. But it could be interesting to see how easy or convoluted could be to program using Rails, and to study the internal implementation.

So, in my Windows machine, some weeks ago, I installed Rails 4.x, using

http://guides.rubyonrails.org/getting_started.html

Using:

gem install rails --no-rdoc --no-ri

I added –no-rdoc, –no-ri to skip the generation of local documentation.

It was a long output, see the gems that were installed:

Fetching: i18n-0.6.5.gem (100%)
Fetching: tzinfo-0.3.37.gem (100%)
Fetching: minitest-4.7.5.gem (100%)
Fetching: atomic-1.1.14.gem (100%)
Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
Fetching: thread_safe-0.1.3.gem (100%)
Fetching: activesupport-4.0.0.gem (100%)
Fetching: builder-3.1.4.gem (100%)
Fetching: actionpack-4.0.0.gem (100%)
Fetching: activemodel-4.0.0.gem (100%)
Fetching: arel-4.0.0.gem (100%)
Fetching: activerecord-deprecated_finders-1.0.3.gem (100%)
Fetching: activerecord-4.0.0.gem (100%)
Fetching: mail-2.5.4.gem (100%)
Fetching: actionmailer-4.0.0.gem (100%)
Fetching: thor-0.18.1.gem (100%)
Fetching: railties-4.0.0.gem (100%)
Fetching: bundler-1.3.5.gem (100%)
Fetching: sprockets-2.10.0.gem (100%)
Fetching: sprockets-rails-2.0.0.gem (100%)
Fetching: rails-4.0.0.gem (100%)
Successfully installed i18n-0.6.5
Successfully installed tzinfo-0.3.37
Successfully installed minitest-4.7.5
Successfully installed atomic-1.1.14
Successfully installed thread_safe-0.1.3
Successfully installed activesupport-4.0.0
Successfully installed builder-3.1.4
Successfully installed actionpack-4.0.0
Successfully installed activemodel-4.0.0
Successfully installed arel-4.0.0
Successfully installed activerecord-deprecated_finders-1.0.3
Successfully installed activerecord-4.0.0
Successfully installed mail-2.5.4
Successfully installed actionmailer-4.0.0
Successfully installed thor-0.18.1
Successfully installed railties-4.0.0
Successfully installed bundler-1.3.5
Successfully installed sprockets-2.10.0
Successfully installed sprockets-rails-2.0.0
Successfully installed rails-4.0.0
20 gems installed

It is interesting to note there were native extensions, something to explore.

Now, the rails command is in my path. How the install program added the command? Simply. If you have Ruby in your path, you have the bin folder in that list of directories. In my case, c:\Ruby193\bin. Every gem that has global commands, can put in that folder new files. In my case, rails, and rails.bat.

This is the content of the .bat file:

@ECHO OFF
IF NOT "%~f0" == "~f0" GOTO :WinNT
@"ruby.exe" "C:/Ruby193/bin/rails" %1 %2 %3 %4 %5 %6 %7 %8 %9
GOTO :EOF
:WinNT
@"ruby.exe" "%~dpn0" %*

It detects if it can use or not a ‘cmd trick’, see

http://www.robvanderwoude.com/ntfor.php

http://www.msfn.org/board/topic/122357-dpn0/

It launch the ‘rails’ file in the same bin directory, using ruby.exe. The rails file has:

#!C:/Ruby193/bin/ruby.exe
#
# This file was generated by RubyGems.
#
# The application 'railties' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require 'rubygems'

version = ">= 0"

if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then
  version = $1
  ARGV.shift
end

gem 'railties', version
load Gem.bin_path('railties', 'rails', version)

It use rubygems, the Ruby packaging system, see:

http://rubygems.org/

It imports, not directly rails, but railties, using the gem method.

The Gem.bin_path returns the path for ‘railties’, see

http://apidock.com/ruby/Gem/bin_path/class

In my case, the bin-path returns ‘c:\Ruby193\lib\ruby\gems\1.9.1\railties-4.0.0\bin\rails’. The second parameter ‘rails’ indicates the script to run. It is executed using the ‘load’ command:

http://www.ruby-doc.org/core-2.0.0/Kernel.html#method-i-load

load(filename, wrap=false) ? true

Loads and executes the Ruby program in the file filename. If the filename does not resolve to an absolute path, the file is searched for in the library directories listed in $:. If the optional wrap parameter is true, the loaded script will be executed under an anonymous module, protecting the calling program’s global namespace. In no circumstance will any local variables in the loaded file be propagated to the loading environment.

I should study the difference with ‘require’:

http://www.ruby-doc.org/core-2.0.0/Kernel.html#method-i-require

require(name) ? true or false

Loads the given name, returning true if successful and false if the feature is already loaded.

If the filename does not resolve to an absolute path, it will be searched for in the directories listed in $LOAD_PATH ($:).

If the filename has the extension “.rb”, it is loaded as a source file; if the extension is “.so”, “.o”, or “.dll”, or the default shared library extension on the current platform, Ruby loads the shared library as a Ruby extension. Otherwise, Ruby tries adding “.rb”, “.so”, and so on to the name until found. If the file named cannot be found, a LoadError will be raised.

For Ruby extensions the filename given may use any shared library extension. For example, on Linux the socket extension is “socket.so” and require ‘socket.dll’ will load the socket extension.

The absolute path of the loaded file is added to $LOADED_FEATURES ($"). A file will not be loaded again if its path already appears in $". For example, require ‘a’; require ‘./a’ will not load a.rb again.

require "my-library.rb"

require "db-driver"

Any constants or globals within the loaded source file will be available in the calling program’s global namespace. However, local variables will not be propagated to the loading environment.

That ‘rails’ file contains:

#!/usr/bin/env ruby

git_path = File.join(File.expand_path('../../..', __FILE__), '.git')

if File.exists?(git_path)
  railties_path = File.expand_path('../../lib', __FILE__)
  $:.unshift(railties_path)
end
require "rails/cli"

Apparently, the gem loader alters the require path, and the require of ‘rails/cli’ is resolved to ‘c:\Ruby193\lib\ruby\gems\1.9.1\railties-4.0.0\lib\rails’.

Ok, enough for today. Next steps: explore the load of rails, parameters, and create a site.

Keep tuned!

Angel "Java" Lopez

http://www.ajlopez.com

http://twitter.com/ajlopez

February 28, 2012

Ruby On Rails (2): Links, News and resources

Filed under: Links, Rails, Ruby, Ruby on Rails, Web Development — ajlopez @ 10:33 am

Previous Post

More links about this popular Ruby web framework (and some discussions):

Crazy, Heretical, and Awesome: The Way I Write Rails Apps
http://jamesgolick.com/2010/3/14/crazy-heretical-and-awesome-the-way-i-write-rails-apps.html

Rails Went Off The Rails: Why I’m Rebuilding Archaeopteryx In CoffeeScript
http://gilesbowkett.blogspot.in/2012/02/rails-went-off-rails-why-im-rebuilding.html

Frontend Code Doesn’t Have to Suck: 5 Tips for Rails Developers
http://starrhorne.com/2012/02/16/building-front-ends-that-dont-suck-five-tips-for-rails-developers.html

Moving from Sinatra to Rails
http://blog.steveklabnik.com/posts/2012-01-17-moving-from-sinatra-to-rails

ruby-debug in 30 seconds (we don’t need no stinkin’ GUI!)
http://pivotallabs.com/users/chad/blog/articles/366-ruby-debug-in-30-seconds-we-don-t-need-no-stinkin-gui-

What programming language is GitHub written in?
http://www.quora.com/What-programming-language-is-GitHub-written-in

Rails: Presenter Pattern
http://blog.jayfields.com/2007/03/rails-presenter-pattern.html

Ruby/Sinatra/Rails failing at Start
http://support.cloudfoundry.com/entries/515384-ruby-sinatra-rails-failing-at-start

Sinatra vs. Rails
http://stackoverflow.com/questions/3989438/sinatra-vs-rails

Rails Caching Benchmarked: MongoDB, Redis, Memcached
http://nosql.mypopescu.com/post/13493023635/rails-caching-benchmarked-mongodb-redis-memcached

r/CircleJerk
http://lostechies.com/ryanrauh/2012/01/04/circlejerk/
Lately there has been a lot posts about how Ruby on Rails might not follow the best practices.

ActiveRecord (and Rails) Considered Harmful
http://blog.steveklabnik.com/posts/2011-12-30-active-record-considered-harmful

Composition Of Responsibility vs Interface Implementation
http://lostechies.com/derickbailey/2012/01/03/composition-of-responsibility-vs-interface-implementation/
ActiveRecord might truly be a horrible beast with far too many concerns in one given place. I haven’t dug into that source code very much. From what I remember of it, it’s huge and difficult for me to understand (but then, it does a metric-ton-squared of meta-programming, so I guess I’m not surprised that it’s hard for me to understand).

Rails Has Turned Me Into a Cannibalizing Idiot
http://wekeroad.com/2012/01/03/rails-has-turned-me-into-a-cannibalizing-idiot/
Some interesting posts flying around about how ActiveRecord is rotting people’s brains and how Rails is "pants on head retarded". I figured I might as well respond.

spree / spree
https://github.com/spree/spree
Spree is a complete open source e-commerce solution for Ruby on Rails
http://spreecommerce.com

Is it better to use routes or mod_rewrite to forward old URLs?
http://stackoverflow.com/questions/1876843/is-it-better-to-use-routes-or-mod-rewrite-to-forward-old-urls

How to make Rails do not ignore trailing slashes in the routes?
http://stackoverflow.com/questions/6486758/how-to-make-rails-do-not-ignore-trailing-slashes-in-the-routes

SEO, Heroku, Ruby on Rails and removing those darn trailing slashes
http://nanceskitchen.com/2010/05/19/seo-heroku-ruby-on-rails-and-removing-those-darn-trailing-slashes/

El maldito libro de los descarrilados
http://emanuelpeg.blogspot.com/2011/02/el-maldito-libro-de-los-descarrilados.html
Tutorial de Ruby on Rails en castellano

Using Redis with Ruby on Rails
http://jimneath.org/2011/03/24/using-redis-with-ruby-on-rails.html

To Redis or Not To Redis? (Key-Value Stores Part 4)
http://www.engineyard.com/blog/2009/key-value-stores-for-ruby-part-4-to-redis-or-not-to-redis/

Delivering email with Amazon SES in a Rails 3 app
http://robots.thoughtbot.com/post/3105121049/delivering-email-with-amazon-ses-in-a-rails-3-app

Activity Logs and Friend Feeds on Rails & pfeed
http://www.travisdunn.com/activity-logs-and-friend-feeds-on-rails-pfeed

Ruby On Rails español
http://www.youtube.com/cspmoreno

Entrenando con Ruby y RoR
http://recorriendootrosrumbos.blogspot.com/2011/12/entrenando-con-ruby-y-ror.html

Learning how to Learn Rails
http://rails.nuvvo.com/lesson/543-learning-how-to-learn-rails

nicksieger / refactoring-to-rails
https://github.com/nicksieger/refactoring-to-rails
Example of refactoring a Spring/Hibernate application to Rails

Configuration for Rails, the Right Way
http://blog.carbonfive.com/2011/11/23/configuration-for-rails-the-right-way/

Ruby clouds: Engine Yard vs. Heroku
http://www.computerworld.com/s/article/9222258/Ruby_clouds_Engine_Yard_vs._Heroku

Memcached Internals: Memory Allocation, Eviction Policy, Consistent Hashing
http://nosql.mypopescu.com/post/13506116892/memcached-internals-memory-allocation-eviction

Heroku and Rails 3.1
http://bostonrb.org/presentations/heroku-and-rails-31

Ruby on Rails 3.0 Release Notes
http://edgeguides.rubyonrails.org/3_0_release_notes.html

Instalar Ruby on Rails 3 en Windows
http://www.developeando.com/2010/12/instalar-ruby-on-rails-3-en-windows.html

Rails QRCode Generator
http://qrcode.heroku.com/

How do I add a field in Ruby on Rails?
http://stackoverflow.com/questions/1608751/how-do-i-add-a-field-in-ruby-on-rails

Why Bother With Cucumber Testing?
http://www.jackkinsella.ie/2011/09/26/why-bother-with-cucumber-testing.html

Mini reviews of 19 Ruby template engines
http://www.hokstad.com/mini-reviews-of-19-ruby-template-engines.html

Ruby on Rails Tutorial
http://ruby.railstutorial.org/chapters/beginning

Rails Searchable API Doc
http://railsapi.com/

Bundler
http://gembundler.com/
Bundler manages an application’s dependencies through its entire life across many machines systematically and repeatably.

Getting Started with Rails
http://guides.rubyonrails.org/getting_started.html

Updating Ruby / Rails
http://allaboutruby.wordpress.com/2009/08/30/updating-ruby-rails/

My Links
http://delicious.com/ajlopez/rubyonrails

More links about Ruby, Ruby web development, Sinatra, etc… are coming.

Keep tuned!

Angel “Java” Lopez
http://www.ajlopez.com
http://twitter.com/ajlopez

February 7, 2012

Ruby on Rails, Demo Application (1) Creating the Application

Filed under: Ruby, Ruby on Rails, Web Development — ajlopez @ 11:25 am

I wrote a post series about my experience at the past Ruby Fun Day at Buenos Aires, in Spanish:

Mi Día en el Ruby Fun Day with @bendycode

Now, I want to write my learning steps following the chapter 2 of Michael Hartl book Ruby on Rails 3 Tutorial: Learn from Example.

I installed Ruby on my Windows box, using http://rubyinstaller.org/ (more options at http://www.ruby-lang.org/en/downloads/). In Windows, you should install DevKit (a minimalist GNU for windows (mingw)). See Ruby Installer page for link download. The instructions to install it are at http://github.com/oneclick/rubyinstaller/wiki/Development-Kit. (some details in Spanish).

Then, I executed the command (at any command prompt)

gem install rails

that installs Ruby on Rails, a web framework for Ruby. Go to a working directory (in my case c:\Git), and execute

rails

Output:

Then I executed

rails new RailsDemoApp

with output:

Change to the new directory:

cd RailsDemoApp

Now, you have a folder tree like:

Ruby manages gems (package to install and use). Rails itself is a gem. And Rails application have a GemFile that list the gems our new application will use. Just in case we have a new gem to install, execute:

bundle install

Bundle is the new package installer used in Ruby on Rails 3. It reads the GemFile and installs (in Ruby gem directory, in our machine, it’s not per application) the needed gems. Then, you can execute:

bundle show

I configured the current directory (Git\RailsDemoApp) to be a Git repo:

git init
git add .
git commit –m “Initial Commit”

I added a new repository in my GitHub Account using https://github.com/repositories/new:

The new repo: https://github.com/ajlopez/RailsDemoApp

I added and pushed to the remote repo:

git remote add origin git@github.com:ajlopez/RailsDemoApp.git
git push origin master

You can launch the initial server with

rails server

or its shortcut

rails s

See the result at http://localhost:3000

Next steps: adding a simple model (users, micropost), database, views, controllers, scaffolding, and Heroku deploy. Scaffolding (quick CRUD code generation) will be the approach to use in this series, but in a following post series I want to show (and learn ;-) the making of a Rails application, step by step, as in Hartl book.

Keep tuned!

Angel “Java” Lopez
http://www.ajlopez.com
http://twitter.com/ajlopez

November 9, 2011

Ruby On Rails: Links, News and Resources (1)

Filed under: Links, Rails, Ruby, Ruby on Rails, Web Development — ajlopez @ 12:19 pm

http://en.wikipedia.org/wiki/Ruby_on_Rails

Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.

Ruby on Rails was extracted by David Heinemeier Hansson from his work on Basecamp, a project management tool by 37signals (now a web application company).[9] Hansson first released Ruby on Rails as open source in July 2004, but did not share commit rights to the project until February 2005.[10] In August 2006 the framework reached a milestone when Apple announced that it would ship Ruby on Rails with Mac OS X v10.5 “Leopard”,[11] which was released in October 2007.

Ruby on Rails version 2.3 was released on March 15, 2009. Major new developments in Ruby on Rails include templates, engines, Rack and nested model forms. Templates enable the developer to generate a skeleton application with custom gems and configurations. Engines let one reuse application pieces complete with routes, view paths and models. The Rack web server interface and Metal allow one to write optimized pieces of code that route around ActionController.[12]

On December 23, 2008, Merb, another web application framework was launched, and Ruby on Rails announced a commitment to work together. The Ruby on Rails team announced they would work with the Merb project to bring “the best ideas of Merb” into Ruby on Rails 3, ending the “unnecessary duplication” across both communities.[13] Merb was merged with Rails as part of the Rails 3.0 release.[14][15]

Jumpstart your Ruby on Rails 3 applications with rails-templater

http://adventuresincoding.com/2010/07/jumpstart-your-ruby-on-rails-3-applications-with-rails-templater

Rails Wizard

http://railswizard.org/

Why DataMapper?

http://datamapper.org/why

Crafting Rails Applications: Why I wrote this book

http://blog.plataformatec.com.br/2010/12/crafting-rails-applications-why-i-wrote-this-book/

Rails Routing from the Outside In

http://guides.rubyonrails.org/routing.html

Crafting Rails Applications: Expert Practices for Everyday Rails Development

http://pragprog.com/book/jvrails/crafting-rails-applications

Why Rack should matter to .NET developers

http://www.robustsoftware.co.uk/post/2131023052/why-rack-should-matter-to-dot-net-developers

Rack is a layer of abstraction which sits between servers and frameworks. What it brings as a result is greater interoperability between HTTP server implementations and web frameworks. As the author of a HTTP server if you get your server to speak Rack you can now host applications written in several Ruby frameworks, Sinatra and Rails being two of the most well known.

VAN – Noviembre 20 de 2010 – Ruby on Rails

http://www.altnethispano.org/wiki/van-2010-11-20-ruby-on-rails.ashx

By @mario_chavez

Ruby on Rails Tutorial: Learn Rails by Example

http://ruby.railstutorial.org/

Rails for Zombies

http://railsforzombies.org/

Alberto Perdomo Presentations

http://www.slideshare.net/alberto.perdomo

Rails101 Tutorial Ruby on Rails with Relations

http://conceptspace.wikidot.com/blog:19

Nimble Method

http://blog.pluron.com/

Rails 3 Screencasts

http://allaboutruby.wordpress.com/2010/06/27/rails-3-screencasts/

Helicon Zoo — a repository of web frameworks and applications for Microsoft IIS.

http://www.helicontech.com/zoo/

It supports Rails

Rails en la nube se llama Heroku

http://recorriendootrosrumbos.blogspot.com/#!/2011/10/rails-tiene-scaffold-nosotros-usamos.html

Ubuntu 11.10 to support the Cloud Foundry Platform-as-a-Service

http://www.h-online.com/open/news/item/Ubuntu-11-10-to-support-the-Cloud-Foundry-Platform-as-a-Service-1324917.html

From .NET to Ruby: Adventure, Courage, and Joy

http://www.infoq.com/presentations/From-NET-to-Ruby

Why ruby?

http://blog.crowdint.com/2011/02/25/why-ruby.html

La complejidad de Ruby On Rails

http://blog.decisionesinteligentes.com/post/1689598042/la-complejidad-de-ruby-on-rails

A Guide To Starting Your Own Rails Engine Gem

http://coding.smashingmagazine.com/2011/06/23/a-guide-to-starting-your-own-rails-engine-gem/

Java Developers have Loads to Learn from the Rails Community

http://www.theserverside.com/video/Java-Developers-have-Loads-to-Learn-from-the-Rails-Community

Ruby Version Manager (RVM)

https://rvm.beginrescueend.com/

ALT.NET Café – Mayo 13 de 2011 – La Inmortalidad de la Medusa – Web Frameworks

http://www.altnethispano.org/wiki/cafe-2011-05-13-web-frameworks.ashx

Advanced Data Models with Rails

http://net.tutsplus.com/tutorials/ruby/advanced-data-models-with-rails/

Rails Best Practices

http://www.codeschool.com/courses/rails-best-practices

Easy Rails OAuth Integration Testing

http://blog.zerosum.org/2011/03/19/easy-rails-outh-integration-testing.html

Rails 3 Baby Steps – Part 2

http://www.codethinked.com/rails-3-baby-steps-part-2

Radiant / radiant

https://github.com/radiant/radiant/wiki/

Radiant is a no-fluff, open source content management system designed for small teams. It is similar to Textpattern or MovableType, but is a general purpose content management system (not just a blogging engine).

RESTify DayTrader

http://bitworking.org/news/201/RESTify-DayTrader

[RAILS 101] Video Tutorials Ruby On Rails

http://www.codersvenezuela.com/post/rails-101-video-tutoriales-de-ruby-on-rails/25

Rails Installer (for Windows)

http://railsinstaller.org/

Ruby and Rails for Attractive .NET Developers

http://david.ing.name/2010/12/18/ruby-and-rails-for-attractive-net-developers/

kfaustino / rails-templater

https://github.com/kfaustino/rails-templater

Template generator for Ruby on Rails 3 applications

Ruby on Rails Tutorial

http://ruby.railstutorial.org/chapters/beginning

Development Kit: How to install it

https://github.com/oneclick/rubyinstaller/wiki/Development-kit

Rails Searchable API Doc

http://railsapi.com/

Bundler

http://gembundler.com/

Bundler manages an application’s dependencies through its entire life across many machines systematically and repeatably.

Getting Started with Rails

http://guides.rubyonrails.org/getting_started.html

My links

http://delicious.com/ajlopez/rubyonrails

Keep tuned!

Angel “Java” Lopez

http://www.ajlopez.com

http://twitter.com/ajlopez

The Shocking Blue Green Theme Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 56 other followers