Thursday, March 29, 2012

Ruby on Rails First Application

create a new project :: rails new app_name
By default the db adapter will be sqlite. To change that update in the config/database.yml

for mysql use
 adapter: mysql2
 encoding: utf8
 database: db_name
 pool: 5
 username: root
After that update Gemfile in the project route to mysql2 from sqlite
run in command :: bundle install
If the mysql adapter is not found needs to install mysql2

for that please follow the steps

sudo apt-get install libmysql-ruby libmysqlclient-dev
gem install mysql2

After bundle install

create db by

rake db:create

start rails server :: rails server
stop :: ctrl+c

Simple application for blog

Create controller action and views using generate

rails generate controller home index

You need to remove the default page from public, then add route to home controller

rm public/index.html

got to config/routes.rb find “root :to” edit the file to have

Blog::Application.routes.draw do
root :to => "home#index"

Create post table using scaffolding

rails generate scaffold Post name:string title:string content:text

Now a migration file will be created inside db/migrate

rake db:migrate

Now check the db table will be created

Through scaffolding, all the option add, edit, delete, view actions will be added automatically. Now the link to the post can be added inside the home/index.html.erb

<h1>Hello, Rails!</h1>
<%= link_to "My Blog", posts_path %>

link_to create the href link with the post path.

Please check your url debug your self. e.g.

Note :: When ever scaffolding or generate or any rails command is executed stop the rails server before that.


Friday, March 2, 2012

PHP 5.4 Released Providing Built-in webserver

Key Features

  • New syntax like Traits.
  • <?= is now always available, regardless of the short_open_tag ini option
  • Class member access on instantiation has been added, e.g. (new Foo)->bar()
  • Class::{expr}() syntax is now supported.
  • The keyword 'insteadof' is introduced with PHP 5.4 (Traits)
  • Built-in webserver in CLI mode to simplify development workflows and testing
  • Cleaner code base (removal of multiple deprecated language features)

Traits :: mechanism for code reuse in single inheritance languages

Built-in webserver

Added for development purpose only. 

Start Webserver

# php -S localhost:8000

To get a specific document root use

# php -S localhost:8000 -t folder_name/

If a PHP file is given on the command line when the web server is started it is treated as a "router" script for the web server. The script is run at the start of each HTTP request. If this script returns FALSE, then the requested resource is returned as-is. Otherwise the script's output is returned to the browser.