Posts

Showing posts from November, 2011

3 Ruby Tools For Newbies

If you're new to programming in Ruby, here are the 3 tools you must know. Debugger The Ruby debugging tool can be found in the library file debug.rb. This tool will let you run your program one instruction at a time, with pauses in between. At every pause you can examine the values or variables of your code, locate your position in a series of nested commands and/or resume execution. You can also tell the debugger when to stop, more commonly known as breakpoints. Using a debugger varies from programmer to programmer. Just because a debugging facility is available for Ruby, it doesn't mean that a novice programmer should quickly adapt himself to using it at once. There are programmers who are comfortable using a debugger, some aren't. It's a matter of preference but at any rate, it's nice to know that there's a tool available for Ruby. Profiling Eventually, when you start writing longer programs, you'll want to measure how much resource

Discover the 5 Reasons to Adopt Ruby on Rails

A productive framework has changed the rules of web development. Ruby on Rails is a framework innovation: it contains all the ingredients necessary to quickly build a web application performance. It is a tool designed in the spirit of agile development to deliver productivity and flexibility for development teams. Based on the Ruby development language, it has revolutionized the world of web development through its pragmatic approach. Ruby on Rails' philosophy is summarized by two principles: • "Never again" and it saves time, concentration and reduces code size. • "Convention over configuration": it is better to use the conventions that wasting time to configure. The advantages of Ruby on Rails: 1 - Develop faster Ruby on Rails is a compact language provided a clear and concise syntax: it produces less code than its competitors. Less code to produce, so it's less time to code, less error-prone, less code to maintain. Integrated to

Basic Facts About Ruby on Rails Programming Language

The saying "Feels lighter, more agile, and easier to understand" has become the definition for ruby on rails. Many people still don't know that ror is otherwise called as ruby on rails. Let's learn more about the basic facts of ruby on rails, the lightening fast programming language today. David Heinemeier Hansson has created ruby on rails during 2003. Today there are around 1500 contributors in the rails core team who has been extending wonderful features in rails. Ruby on rails helps to develop a website much faster in a simple way. ROR is an interesting framework that has been implemented in almost all web solutions. Famous websites such as BaseCamp, CrunchBase, Github, Hulu, Penny Arcade, Scribd, Spiceworks, Twitter, Urban Dictionary, XING and Yellowpages.com are using ruby on rails. Some of the merits of ruby on rails include: 1. web applications can be performed in a matter of days. 2. dynamic, imperative and reflective 3. object-orien

5 Useful Tips for Ruby on Rails Developers

Ruby on Rails is an open source web application framework for the Ruby programming language. It is specially designed to be used by the web developers for rapid development. Like many web frameworks, Ruby on Rails uses the Model-View-Controller architecture pattern to organize application programming. It includes tools that make common development tasks easier. If you follow the correct conventions, you will be able to avoid lengthy configuration of files and you can have more time to focus on business logic. If you are a developer, here are some useful points I would like to share with you. These points will help to make your jobs easier. • Rails has a well-defined plug-in structure that allows the users to install and use plug-ins in the application easily. David Heinemeier Hansson, the founder of Rails stated that he used 5-6 plug-ins in each Rails application. Being the developer, you don't need to waste your time writing the program. You just need

Caching Techniques that Rails provides by Default

This is an introduction to the three types of caching techniques that Rails provides by default without the use of any third party plug-ins. Page Caching Action Caching Fragment Caching Page caching is a Rails mechanism which allows the request for a generated page to be fulfilled by the web-server (i.e. Apache or nginx), without ever having to go through the Rails stack at all. Page caching is an efficient way to cache stateless content. Obviously, this is super-fast. Unfortunately, it can’t be applied to every situation (such as pages that need authentication) and since the webserver is literally just serving a file from the filesystem, cache expiration is an issue that needs to be dealt with. class ProductsController < ActionController caches_page :index def index @products = Products.all end def create expire_page :action => :index end end     One of the issues with Page Caching is that you cannot use it for pages that req

Create New Rails Application with MongoDB

Create a New Rails Application with MongoDB # Use sudo if your setup requires it gem install rails   Create New Rails Application by skipping the Active Record rails new awesome_app --skip-active-record   This is the gem file and the list of the required gems for MongoDB require 'rubygems' require 'mongo' source :rubygems gem 'mongo_mapper' gem 'rails', '3.0.3' gem 'devise', '1.1.3' gem 'devise-mongo_mapper', :git => 'git://github.com/collectiveidea/devise-mongo_mapper' group :test, :development do [whatever testing gems you want in here] end     Then Run bundle install to install all the gems mentioned in the gem file.   $ bundle install   There's two initializer files we'll need. We add the one for mongo,  which I put in config/initializers/mongo.rb: # config/initializers/mongodb.rb include MongoMapper db_config = YAML::load(File.read(File.join(Rails.root, "/config/

Capistrano Setup and Deploy file options

You will need to install the Capistrano gem and its dependencies sudo gem install capistrano  Always keep in mind that Capistrano runs on your local machine. It uses Net::SSH and Net::SFTP to connect to your remote servers and run shell commands on them. This means you do not need to install Capistrano on your remote servers, only on the machines you want to use to trigger a deploy. Capistrano uses a Rake-like syntax for defining tasks that will execute on the server. Each task has a name, followed by a code block. Every time you deploy, Capistrano creates a new folder named with the current date and then checks out your entire Rails app into that folder. Next, it wires the whole thing together with several symbolic links Notice the current directory doesn’t have the physical file structure underneath it. current directory is only a link into a specific dated folder in the releases directory. The result is that current will always hold the current active version of you

Capistrano : A Brief Introduction

Capistrano is a Ruby gem designed to execute tasks on one or more remote machines. You’ll need SSH access to use Capistrano. Capistrano, affectionately known as Cap, automates the deploy process. We can use cap to take our code from some a repo and push it to the server, stop/start/restart the server, write custom tasks required by our application (think install required gems), or disable/enable a maintenance page. Using cap is not required but it sure beats using FTP to copy all the files around! Cap’s real power comes from the ability to write custom tasks in Ruby to manipulate the server. We’ve written a lot of applications that allow user file uploads. Then on the server side, some directory needs to be created with proper permissions for the uploads to succeed. It’s easy enough to write a cap task to create the directory and set the permissions. Then, if you ever change servers, you can simply run the cap task to setup the server again. There are many things you can do with C

Fixing readline for the Ruby on Rails console

Fixing readline for the Ruby on Rails console $ rails console /home/user/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb/completion.rb:9:in `require': no such file to load -- readline (LoadError) from /home/user/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb/completion.rb:9:in ` ' from /home/ user /.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/commands/console.rb:3:in `require' from /home/ user /.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/commands/console.rb:3:in ` ' from /home/ user /.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/commands.rb:20:in `require' from /home/ user /.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/commands.rb:20:in ` ' from script/rails:6:in `require' from script/rails:6:in ` ' The problem is that Ruby is somehow not cofigured to load the readline library and thus cannot run its console. This is a downside of using a language specific package manager, sepe

MongoDB : An Introduction

MongoDB is an open-source, high-performance, document-oriented database. Documents are JSON-like data structures stored in a format called BSON (bsonspec.org). Documents are stored in Collections, each of which resides in its own Database. Collections can be thought of as the equivalent of a table in an RDBMS. There are no fixed schemas in MongoDB, so documents with different “shapes” can be stored in the same Collection. MongoDB features full index support (including secondary and compound indexes); indexes are specified per-Collection. There is a rich, document-based query language (see reverse) that leverages any indexes you've defined. MongoDB also provides complex atomic update modifiers (see reverse) to keep code contention-free. Clustered setups are supported, including easy replication for scaling reads and providing high availability, as well as auto-sharding for write-scaling and large data-set sizes.

MongoDB : Setup

First Download the mongodb  using these commands $ curl http://downloads.mongodb.org/linux/mongodb-linux-i686-1.6.4.tgz > mongo.tgz $ tar xzf mongo.tgz   By default MongoDB will store data in /data/db, but it won't automatically create that directory. To create it, do: $ sudo mkdir -p /data/db/ $ sudo chown `id -u` /data/db   You can also tell MongoDB to use a different data directory, with the --dbpath option. First, start the MongoDB server in one terminal: ./mongodb-xxxxxxx/bin/mongod   To install MongoDB shell. sudo apt-get install mongodb  

Heroku : Complete Setup

Heroku Setup For your Rails application   Create Heroku Account Then you need to install Heroku Gem in your application , if you are using RVM then you need to run gem install heroku Or you can use bundler to install heroku by mentioning that in the Gemfile gem 'heroku' Then you need to add your Public key to the Heroku Account. ssh-keygen -t rsa -f ~/.ssh/your_name -C "your-email@domain.com" You can use this command to create a new pair of public and private keys and you can give keys a unique name , if you are already using a keys and wanted to create a new one. After that you need to login to heroku from your terminal by using heroku login After that you need to enter your email address and password which you have created for your heroku account. Once you logged in to your Heroku Account from your terminal , you need to add the key which you have created to that account , you can do this by heroku keys:add /path_to/.ssh/your_name.pub Onc

Rails Architecture : Model , Views and Controllers

In a Rails application, incoming requests are first sent to a router, which works out where in the application the request should be sent and how the request itself should be parsed. Ultimately, this phase identifies a particular method (called an action in Rails parlance) somewhere in the controller code. The action might look at data in the request itself, it might interact with the model, and it might cause other actions to be invoked. Eventually the action prepares information for the view, which renders something to the user. The model is responsible for maintaining the state of the application. Sometimes this state is transient, lasting for just a couple of interactions with the user. Sometimes the state is permanent and will be stored outside the application, often in a database. A model is more than just data; it enforces all the business rules that apply to that data. For example, if a discount shouldn’t be applied to orders of less than $20, the model will e