by http://webgeektutorials.blogspot.com
Showing posts with label Ruby. Show all posts
Showing posts with label Ruby. Show all posts

Monday, September 19, 2011

Pakyow : Web framework for Ruby

Web framework Pakyow follows the MVC design pattern, but the flow is a bit different than what you might be used to. When a request is received the views are assembled first (based on the URL). If a route matches the appropriate business logic is invoked. The business logic can then manipulate the view and bind data to it.

Some Advantages :
  • In Pakyow, views define what the application will present. They are 100% HTML and no template language or special tags are needed to construct the view layer.
  • View construction begins with a root view, which usually defines the general view structure. Containers are created in the root view, which define the parts of the structure that are generated dynamically. Creating a container is as easy as adding an "id" attribute to any tag.
  • Pakyow provides several ways for the business logic of an application to easily interact with the views. In most frameworks the view logic is contained in the view itself, but Pakyow separates views and view logic. This keeps the roles for design and developer clearly defined and minimizes conflicts.
  • View construction happens before the business logic is invoked. The views can then be manipulated even easier than using a template language.
  • Data can easily be bound to its view.

Wednesday, July 13, 2011

MySql Best Opensource Database for Ruby on Rails

RoR is being highly discussed phrase in the realm of web development. Thinking why is it so? Ruby on Rails can be defined as a full stack framework which means that this framework covers everything which is needed to build a web application. It is an open source web application framework that can help you building web applications with an out of the box architecture. It is written in Ruby which is an object oriented language with clean syntax that can make programming enjoyable. Moreover Rails could help you creating a web application almost ten times faster than you do with regular java framework and that too without compromising with the quality. As it uses the MVC architecture pattern, it organizes the application programming that provides flexibility and simplicity. RoR is a great framework for them who have high timeliness and budget constraint.

While SQLite3 is extremely convenient for development and testing databases, and PostgreSQL has powerful Generalized Search Tree indexes and is very close to being enterprise-ready, MySQL is the choice for many Web sites thanks to its excellent read performance, transparent support for large text and binary objects, and incredibly easy administration. Stored procedures, functions, triggers, and updateable views were added to MySQL in version 5, overcoming the largest technical objections to its deployment at many sites. MySQL also has a large, helpful user base, and some poster-child deployments including eBay, Yahoo, and Craigslist.
You can download MySql module for ruby on rails from link given below.

Thursday, June 16, 2011

View in Ruby

Use the Ruby command ruby script/generate controller Hello:
ruby script/generate controller Hello

Creating an Action
//Edit hello_controller.rb under \app\controllers

class HelloController < ApplicationController
                 def there...............
end
end

//To establish a view template for the hello controller's there action, you can create a file named there.rhtml and store it in the
//\app\views\hello directory.

Ruby: Unit Testing


Unit Testing is a great way to catch errors early in the development process, if you dedicate time to writing appropriate and useful tests. As in other languages, Ruby provides a framework in its standard library for setting up, organizing, and running tests called Test::Unit.
There are other very popular testing frameworks, rspec and cucumber come to mind.
Specifically, Test::Unit provides three basic functionalities:
  1. A way to define basic pass/fail tests.
  2. A way to gather like tests together and run them as a group.
  3. Tools for running single tests or whole groups of tests.
Writing a UNIT TEST 
require 'test/unit'

class Person
attr_accessor :first_name, :last_name, :age

def initialize(first_name, last_name, age)
raise ArgumentError, "Invalid age: #{age}" unless age > 0
@first_name, @last_name, @age = first_name, last_name, age
end

Wednesday, May 18, 2011

Active Record - Save without callbacks

p = Post.first

p.title = "test"

p.send(:update_without_callbacks)



for sharing this information..

Wednesday, May 11, 2011

Ruby on rails : Array Pagination

Will_paginate is very well designed plug-in. Besides Active-record object integration, it can integrate with array and any collection that you may have. Paginate an Array using will paginate..

Add this as method,

Array.class_eval do
def paginate(page=1, per_page=15)
pagination_array = WillPaginate::Collection.new(page, per_page, self.size)
start_index = pagination_array.offset
end_index = start_index + (per_page - 1)
array_to_concat = self[start_index..end_index]
array_to_concat.nil? ? [] : pagination_array.concat(array_to_concat)
end
end

And with the array @results do @results.paginate
And with the array @results do @results.paginate

reference: http://www.devchix.com/2007/07/23/will_paginate-array/

Wednesday, March 16, 2011

Ruby : Google map, markers and bounds

You can use a function to load Google map with Marker and bounds, function is as below.

function initialize(lat, lon, div_id) {
var myLatlng = new google.maps.LatLng(lat, lon);
var myOptions = {
zoom: 8,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var bounds = new google.maps.LatLngBounds ();
var map = new google.maps.Map(document.getElementById(div_id), myOptions);
var trucklatlng = new google.maps.LatLng(lat,lon);
var marker = new google.maps.Marker({
position: trucklatlng,
map: map,
title:"Assist"
});

Tuesday, March 8, 2011

Multiple Database Connection in Ruby on Rails

Ruby on Rails sets up the connection depending on your application’s database.yml file. In database.yml file you set up configration environmentwise.

As I active record allow to access single database but you want to access more than one databases than it required to have multiple connection at a time. Now you think that how this possible. So Rails provides gem to implement you need. Follow the below steps:

1. Install gem
sudo gem install magic_multi_connections

2. After installing gem there is one patch required in connected.rb(/usr/lib/ruby/gems/1.8/gems/magic_multi_connections-1.2.1/lib/magic_multi_connections/connected.rb)
replace

raise NameError.new ( "uninitialized constant # (const_id)") unless
target_class

with

Friday, February 11, 2011

How well you know Interactive Ruby Shell?

The Interactive Ruby Shell, more commonly known as IRB, is one of Ruby's most popular features, especially with new developers. You can bash out a one-liner, try a method you've just learned about, or even build a small algorithm or two without going the whole way to writing a complete program.
I've started learning ruby, so while I've been digging through some of the best content I can find on IRB learning all about its internals and ways to get more out of it and big thanks to all of those guys who contributed great knowledge on web, thought I should share some of best contents gathered :

Try out some trick in your IRB console:

irb> Kernel.methods.each do |method| puts method; system "/usr/local/bin/ri --no-pager Kernel##{method}"; ch = STDIN.getc; break if (ch.chr == 'q') end

Once you enter this just keep hit enter until you want to quit, at that point hit ‘q’ and enter.


How to clear IRB console ?

On Mac OS X or Linux you can use Ctrl + L to clear the IRB screen. But in windows i don't know how but yes i know the dos command 'cls' which clears screen. so simply i'm calling this command using system.

Monday, February 7, 2011

Developing iPhone app using Ruby on Rails

This article focused on the structure needed to support separating content for iPhone and iPod touch users, very well written by Noel Rappin. It covered how to manage the viewport to display Mobile Safari content at the right size and scale, and started to discuss what to place in the basic layout of your mobile site.
Part 2 covers how to display your content in a Mobile Safari browser. It also looks at the UI guidelines for managing iPhone content and explores how to make those guidelines come to life in your own Rails application.

Follow these links :
Developing iPhone applications using Ruby on Rails Part 1
Developing iPhone applications using Ruby on Rails Part 2
Developing iPhone applications using Ruby on Rails Part 3

Noel Rappin is the vice president of the Rails practice at Pathfinder Development (http://www.pathf.com), and has a decade of experience with web application development. He has a doctorate from the Georgia Institute of Technology, where he studied how to teach Object-Oriented design concepts. He is the author of Professional Ruby on Rails, and the co-author of wxPython in Action and Jython Essentials. Read more at http://www.pathf.com/blogs and http://10printhello.blogspot.com.

Monday, January 10, 2011

Ruby Cheat Sheet

A quick reference guide for Ruby , containing the default directory structure, predefined variables, methods, reserved words and regular expression syntax.
The Ruby cheat sheet is designed to be printed on an A4 sheet of paper and live by a developers desk, to make life a bit easier. A description of what is on the cheat sheet follows, or if you are impatient, you can go straight to the full size Ruby cheat sheet.
Ruby on Rails includes tools that make common development tasks easier "out of the box", such as scaffolding that can automatically construct some of the models and views needed for a basic website. Also included are WEBrick, a simple Ruby web server that is distributed with Ruby, and Rake, a build system, distributed as a gem. Together with Ruby on Rails these tools provide a basic development environment.

Ruby on Rails Cheat Sheet

A quick reference guide for Ruby on Rails, containing the default directory structure, predefined variables, methods, reserved words and regular expression syntax.
The Ruby On Rails cheat sheet is designed to be printed on an A4 sheet of paper and live by a developers desk, to make life a bit easier. A description of what is on the cheat sheet follows, or if you are impatient, you can go straight to the full size Ruby On Rails cheat sheet.

Tuesday, December 28, 2010

Which Web Language?

When choosing web design languages, make sure you take some time to research your options to ensure you're making the best choice for your project.
When you think about the language you are using to design your website keep in your mind “what is important about web design language, and what part of web design efforts can you take or leave?”.
If you like to create and publish your own web or blog, your first step should be to decide what type of web you would like to create and what web design language you would like to use.

 

Hypertext Markup Language (HTML)

HTML, which stands for HyperText Markup Language, is the predominant markup language for web pages. A markup language is a set of markup tags, and HTML uses markup tags to describe web pages.
This language is so simple you can type the syntax into a text editor, such as Notepad, save it with an .html extension and instantly have a web page. HTML can also be used to include Cascading Style Sheets (CSS) to define the appearance and layout of text and other material. The W3C, maintainer of both HTML and CSS standards, encourages the use of CSS over explicit presentational markup