Ruby on Rails Programming Tips

Next Step : Creating Empty Applications

Now that all has been set-up and is working, you should be able to create empty apps which is merely defining the application using rails which automatically creates all the necessary directories that are needed. Open a command prompt window and go to the directory where it was installed and proceed into the rails_apps directory. Type in ‘rails filename’ and rails creates all the necessary directories you would be needing for the development process. Don�t get freaked out when you see the multitude of directories for they will be filled out by “RAILS” and not by you manually. The next post will discuss some of the nuances of those dizzying directories to take some of the fog over them out.

Simplifying the previous program with modifiers

As said in the past post, there is an easier way of doing the stuff we did in the last program which would be very helpful when coding thousands of line of code when you do end up building your own programs is ruby.

class BookList
def [](key)
if key.kind_of?(integer)
result = @Books[key]
else
result = @Books.find { |aBooks| key == sBooks.name}
end
return result
end
end

Simplifying the code further by using the ‘if’ statement as a modifier it becomes a shorter easier to attain the same results as with the first program:

class Booklist
def [](key)
return @Books[key] if key.kind_of?(Integer)
return @Books.find { |aBooks| aBooks.name == key }
end
end

The use of the ‘find’ command in Ruby is simply a call to a function that is executed and it can be compared to a block call in many other languages such as Perl, C++ or Java.

Using the ‘yield’ statement

It might be almost similar but relatively different in a big way for blocks may appear only in the source adjacent to a method call which means it should be written on the same line as the method’s last parameter and it is not implemented once it is encountered but, Ruby rather remembers the context by which the block of code appears then enters the method. Within the method itself, the block of code may be called as if it were a block in itself by using the ‘yield’ statement. After the block of code has been executed, control returns immediately right after the call to the yield statement. Sample use of ‘yield’:

def threeTimes
yield
yield
yield
end
threeTimes {puts “Hi There”}

About Ruby on Rails

An open source web application framework written in Ruby is commonly known as RoR (Ruby on Rails). It was designed to make web development faster, simpler and more efficient and it also used to develop real-world application with less code, compared to other application frameworks. Ruby on Rails divides itself into various packages, namely Active Record, Active Resource, Action Pack, Active Support and Action Mailer.

Ruby on Rails Chases Simplicity in Programming

Ruby on Rails has focused on creating templates and designs that tackle the unglamorous problems. It is not also to create a sophisticated development framework that the engineers at Google or Amazon.com will flock to; it is like making a database modification that the great majority of Web developers face every day.

How to Install Ruby on a Shared Web Host

by Chubs

webhosting.jpg

Create a directory for all of the software you are going to download and installed. In this example, the created directory is “temp” at the root of the files system, but you can use any name and location you like.

cd /
mkdir temp
chmod 775 temp

Now, download, configure and install Ruby. You can download the latest stable source tarball for Ruby here. Wget is used in this example:

cd temp
wget ftp://ftp.ruby-lang.org/pub/ruby/ruby-1.8.2.tar.gz
tar -zxvf ruby-1.8.2.tar.gz cd ruby-1.8.2

Specify an install directory since there are times when you won’t have permissions to install things in normal directories. Here, we can see the “configure” script for Ruby, creating a directory inside “/usr/local” for installation:

./configure –prefix=/usr/local/ruby –exec-prefix=/usr/local/ruby

Now, you have a Makefile that you can compile:

make
make install

Your Ruby is now installed. You should try making a symbolic link to Ruby somewhere in your local path:

ln -s /usr/local/ruby/bin/ruby /usr/local/bin/ruby

How to Install RubyGems and Rails on a Shared Web Host

by Chubs

webweb.jpg

RubyGems or Gem allows you to install extra packages and libraries for Ruby. You need Gem before installing Rails. You can get the latest version of RubyGems here.

cd /temp
wget http://rubyforge.org/frs/download.php/3700/rubygems-0.8.10.tgz
tar -zxvf rubygems-0.8.10.tgz
cd rubygems-0.8.10

To install RubyGems, you need to use Ruby to call the setup script:

ruby setup.rb

Here, you should see “Successfully built RubyGem” if it’s finished. Next, open the file “/usr/local/ruby/bin/gem” in your favorite text editor (such as vi) and edit the first line so you’ll know where to find your custom Ruby installation. Example:

#!/usr/local/bin/ruby

Now, add a few more symlinks:

cd /usr/local/bin
ln -s /usr/local/ruby/bin/erb erb
ln -s /usr/local/ruby/bin/eruby eruby
ln -s /usr/local/ruby/bin/gem gem
ln -s /usr/local/ruby/bin/gem_server gem_server
ln -s /usr/local/ruby/bin/testrb testrb
ln -s /usr/local/ruby/bin/update_rubygems update_rubygems

RubyGems is now installed. To install Rails, use:

gem install rails –remote

Ruby – Still on the Sidelines?

Ruby has long been fighting for recognition in the world of open-source development and in the past few years, it surely has managed to go mainstream with some major development projects. One surprising fact when it comes to overall popularity, recent development surveys show that use of the scripting language has jumped by 40% which may be sign that people are embracing more options in their drive to lower all costs with regard to the newer versions of the many flavors being used all over the globe. The updated Ruby on Rails 2.3 is a bit better and easier to use compared to previous to older versions and with the recession putting the brakes on many projects being planned, alternate methods of development and deployment have to be found to allow enterprise to continue with their plans with less costs. Keep on reading!

Rails 2 – Enterprise Ready

From the recently concluded RailsConf 2009, the many core Rails developers have made it known that Ruby on Rails 2.0 is indeed enterprise ready for use on the net. As with many of the open-sourced languages being used the world over, security remains to be one of the greatest concerns due to the open nature that is counter-intuitive for most enterprise development projects who need their information secured in more ways than one. Another good point given light was the ability of the current version to scale meaning adapt with changing conditions that allows easy upgrades allowing more people to use without much fuss. Keep on reading!

Mac’s and Ruby – Nice!

The somewhat hidden world of the Mac from Apple has remained in place as one of the alternate PC manufacturers the world over. Many have been forecasting the demise of the computer maker but with their venture into other avenues such as the multimedia gadget market and others have allowed them to remain a figure in the computing industry. Thous everybody knows that Mac’s are overall more stable than PC’s there are still not enough versions of popular software available for Macs compared to other computing platforms. Keep on reading!