Friday, June 29, 2007

UJS for Rails

Unobtrusive Javascript for Ruby On Rails

UJS for Rails makes it easy to apply behaviour to your page. Simply specify the element(s) of your page that you want the behaviour to apply to using CSS-style selectors and the event that you want to trigger the behaviour, and the Javascript that you want to run. In addition, you can write your behaviours using RJS-style Ruby to Javascript proxies.

Installation

You can install the UJS plugin from our Subversion repository with Rails’ plugin script:

ruby script/plugin install http://source.ujs4rails.com/current/unobtrusive_javascript

After Installing the plugin, run the following command

rake unobtrusive_javascript:install

If "
lowpro.js" is copied to your system means, installation is perfect...otherwise
please do the installation again :)

Once you’ve confirmed that lowpro.js is installed, the final
installation step is to open your routes.rb file and add the following
line into the Routes.draw block


ActionController::Routes.draw do |map|
UJS::routes
# your routes here.
end

Including The Scripts

Simply use javascript_include_tag to add the UJS scripts into the document’s head tag as shown:
<%= javascript_include_tag 'prototype', :unobtrusive %>

You can safely use :defaults and :unobtrusive together in the same javascript_include_tag call.
Applying Behaviours

apply_behaviour(css_selector, javascript, options={})

The first argument of apply_behaviours is an event:Selectors style selector that specifies both the CSS selector for the elements to target and the event to attach the behaviour to in this format: css_selector:event

The second argument is the behavior to apply. Pass a string to specify the JavaScript code to execute directly. There are two variables available to the behaviour JavaScript. In the JavaScript code, this refers to the triggering element and event refers to the JavaScript event object.

For Documentation, please refer this url -

http://www.ujs4rails.com/resources/usage-documentation

Note: UJS (and the lowpro extensions) requires at least Prototype 1.5.0 RC0.

Wednesday, June 20, 2007

finder_sql in HABTM

Using this "finder_sql", you can override ActiveRecord's associations in your models. Use it to manually specify the association that should be returned.

Important Note: if you need to do any variable interpolation in the string , make sure to use single quotes instead of the usual doubles:

has_many :books, :finder_sql => 'select * from books where author_id=#{id}'

When you use double quotes, the string interpolation happens immediately (when the class is first loaded), thus obtaining the object ID of the class in memory. Using single quotes, the interpolation occurs within the context of your object instance, which is what you're expecting.

Enjoy Agile Programming!!!

Tuesday, June 12, 2007

Safari for Windows










Apple is releasing the public beta of Safari for Windows today.

Steve gave demos of Safari, claiming that it screams:

  • ibench html performance: IE 4.6 sec, FF 3.7, Safari 2.2 seconds
  • javascript: IE 2.4 sec, FF 1.6, Safari 0.9 seconds

Safari has always been the fastest browser on the Mac and now it’s the fastest browser on Windows, loading and drawing web pages up to twice as fast as Microsoft Internet Explorer 7 and up to 1.6 times faster than Mozilla Firefox 2.

Monday, June 11, 2007

Google Gears

Google announced an early beta of Gears, a "browser extension that enables web applications to provide offline functionality using following JavaScript APIs:
  • Store and serve application resources locally
  • Store data locally in a fully-searchable relational database
  • Run asynchronous Javascript to improve application responsiveness"

Google Gears is an open source browser extension that lets developers create web applications that can run offline. Gears provides three key features:

  • A local server, to cache and serve application resources (HTML, JavaScript, images, etc.) without needing to contact a server
  • A database, to store and access data from within the browser
  • A worker thread pool, to make web applications more responsive by performing expensive operations in the background

Google Gears is currently an early-access developers' release. It is not yet intended for use by real users in production applications at this time.

Google Gears extends browsers by making new APIs available to JavaScript code. Like all APIs, they must be used explicitly. To take advantage of the offline features provided by Google Gears, you'll need to add or change code in your web application.

Only web sites that have been specifically designed to use Google Gears can take advantage of its offline capabilities.

Friday, June 01, 2007

Rails Rake Tasks Reference

rake cache:clear
# Clears all cached pages
rake db:bootstrap
# Loads a schema.rb file into the database and then loads the initial database fixtures.
rake db:bootstrap:copy_default_theme
# Copy default theme to site theme
rake db:migrate
# Migrate the database through scripts in db/migrate. Target specific version with VERSION=x
rake db:schema:dump
# Create a db/schema.rb file that can be portably used against any DB supported by AR
rake db:schema:load
# Load a schema.rb file into the database
rake db:bootstrap:load
# Load initial database fixtures (in db/bootstrap/*.yml) into the current environment's database. Load specific fixtures using FIXTURES=x,y
rake db:fixtures:load
# Load fixtures into the current environment's database. Load specific fixtures using FIXTURES=x,y
rake db:sessions:clear
# Clear the sessions table
rake db:sessions:create
# Creates a sessions table for use with CGI::Session::ActiveRecordStore
rake db:structure:dump
# Dump the database structure to a SQL file
rake db:test:clone
# Recreate the test database from the current environment's database schema
rake db:test:clone_structure
# Recreate the test databases from the development structure
rake db:test:prepare
# Prepare the test database and load the schema
rake db:test:purge
# Empty the test database
rake deploy
# Push the latest revision into production using the release manager
rake diff_from_last_deploy
# Describe the differences between HEAD and the last production release
rake doc:app
# Build the app HTML Files
rake doc:clobber_app
# Remove rdoc products
rake doc:clobber_plugins
# Remove plugin documentation
rake doc:clobber_rails
# Remove rdoc products
rake doc:plugins
# Generate documation for all installed plugins
rake doc:rails
# Build the rails HTML Files
rake doc:reapp
# Force a rebuild of the RDOC files
rake doc:rerails
# Force a rebuild of the RDOC files
rake edge
# freeze rails edge
rake log:clear
# Truncates all *.log files in log/ to zero bytes
rake rails:freeze:edge
# Lock to latest Edge Rails or a specific revision with REVISION=X (ex: REVISION=4021) or a tag with TAG=Y (ex: TAG=rel_1-1-0)
rake rails:freeze:gems
# Lock this application to the current gems (by unpacking them into vendor/rails)
rake rails:unfreeze
# Unlock this application from freeze of gems or edge and return to a fluid use of system gems
rake rails:update
# Update both configs, scripts and public/javascripts from Rails
rake rails:update:configs
# Update config/boot.rb from your current rails install
rake rails:update:javascripts
# Update your javascripts from your current rails install
rake rails:update:scripts
# Add new scripts to the application script/ directory
rake remote_exec
# Execute a specific action using the release manager
rake rollback
# Rollback to the release before the current release in production
rake show_deploy_tasks
# Enumerate all available deployment tasks
rake stats
# Report code statistics (KLOCs, etc) from the application
rake test
# Test all units and functionals
rake test:functionals
# Run tests for functionalsdb:test:prepare

rake test:integration
# Run tests for integrationdb:test:prepare
rake test:plugins
# Run tests for pluginsenvironment

rake test:recent
# Run tests for recentdb:test:prepare
rake test:uncommitted
# Run tests for uncommitteddb:test:prepare

rake test:units
# Run tests for unitsdb:test:prepare
rake tmp:cache:clear
# Clears all files and directories in tmp/cache
rake tmp:clear
# Clear session, cache, and socket files from tmp/

rake tmp:create
# Creates tmp directories for sessions, cache, and sockets

rake tmp:pids:clear
# Clears all files in tmp/pids

rake tmp:sessions:clear
# Clears all files in tmp/sessions

rake tmp:sockets:clear
# Clears all files in tmp/sockets
rake update_dialog_helper
# Copies the latest dialog.js to the application's public directory