The Web’s Funniest Error Messages

Nice images collection on Mashable


Learning Rails – step 5

In this step:
- using “Flash Message Conductor” (http://swik.net/Rails/Robby+on+Rails/Flash+Message+Conductor+now+a+Gem/c39as) I managed messages and errors.

- using javascript + css I managed row highlight both in contacts view and mailinglists view

<!-- _row.html.erb <== contacts view -->
<tr class="<%= cycle('oddrow','evenrow') %>" onmouseover="cell_over(this, 'TrHover')" onmouseout="cell_out(this)">
<td>< %=h row.email %></td>
<td>< %=h row.firstname %></td>
<td>< %=h row.lastname %></td>
<td>< %=h row.privacy %></td>
< %= link_to 'Edit', :controller => 'contacts', :action => :edit, :id => row.id %>
< %= link_to_remote 'Delete',
:update => 'container',
:url => { :action => :destroy, :id => row.id},
:confirm => 'Are you sure?', :method => :delete

 * mouseover.js
 * @author massimo
function cell_over(cell, classname) {
	if (document.all || document.getElementById) {
	cell.classBackup = cell.className;
	cell.className = classname;

function cell_out(cell){
	if (document.all || document.getElementById) {
	cell.className = cell.classBackup;

- using Ajax I managed “new contact”

<%= javascript_include_tag :defaults %>
<% form_remote_tag(:url => {:action => 'create'},
:html => {:id => 'contact_form'}) do %>
<div id="contact_para">
<%= text_field "contact", "email" %>
<%= text_field "contact", "firstname" %>
<%= text_field "contact", "lastname" %>
<%= check_box "contact", "privacy" %>
<%= submit_tag 'Add' %>
<% end %>

The below video show the site functionality.

Download Step 5: Flv formatOgg format

You can download the source developed till now clicking here.


Learning Rails – step 4

In the 2 following video you can see how to create pages accessible only to logged in users.

Download Step4 – 1st: Ogg formatAvi format

Download Step4 – 2nd: Ogg formatAvi format

You can download the source developed till now clicking here.


Learning Rails – step 3

Hi all.
To manage users, instead of reinvent the wheel, we can use Ruby on Rails plugins. The web site Agile Web Development contains a complete list of plugins. In home page, in the “browse by tag” section, you can click on “authentication” and then select “Restful-authentication”.
The Restful-authentication plugin provides a foundation for managing user authentication:
* Login / logout
* Secure password handling
* Account activation by validating email
* Account approval / disabling by admin
* Rudimentary hooks for authorization and access control.

Ok, now we have to install the plugin:

  • get the repository url from the plugin web page
  • open a console and change the directory to the website directory
  • type the command script/plugin install

When the command terminates you will find the plugin installed into the directory “vendors/plugins”

Open the previous console window and follow the below steps:
Run the generator
The generator sets up your controllers, model, views and observer as well as modify the routes.rb file (sets up session and users as resources). The session controller is used for signing in and out of the system while the user controller takes care of the rest. We also include the user account activation system.

 ruby script/generate authenticated user sessions

Run the migration
The system also generated a migration file. Run the migration with:

 rake db:migrate

Modify the routes file
Open up config/routes.rb and add to the named route section:

 map.activate '/activate/:activation_code', :controller => 'users', 
        :action => 'activate'

While the routes file is still open, add more named routes (giving the user actions nice, friendly urls)

 map.signup '/signup', :controller => 'users', :action => 'new'
 map.login '/login', :controller => 'sessions', :action => 'new'
 map.logout '/logout', :controller => 'sessions', :action => 'destroy'

Add an observer
Add an observer to config/enviroment.rb (within the Rails::Initializer.run block) :

 config.active_record.observers = :user_observer

At this point, the basic system should be working. Start up your development server and go to http://localhost:3000/signup. Also try http://localhost:3000/login to confirm it’s fine.

Set up ActionMailer
The rails config/environment.rb file includes a Rails::Initializer.run block and prior to Rails 2, configuration code went in there.
With Rails 2, there’s now a directory (config/initializers) where seperate, discreet bits of configuration are placed in files of their own.
These are automatically loaded after plugins are loaded when Rails starts up.Create a new file called mail.rb in the config/initializers directory.
Place the following SMTP settings into the mail.rb file:

 ActionMailer::Base.delivery_method = :smtp
 ActionMailer::Base.smtp_settings = {
	:address => "mail.example-domain.com",
	:port => 25,
	:domain => "www.example-domain.com",
	:authentication => :login,
	:user_name => "user@example-domain.com",
	:password => "secret"

:address and :port – Determines the address and port of the SMTP server you’ll be using. These default to localhost and 25 , respectively.
:domain – The domain the mailer should use when identifying itself to the server (usually the top-level domain name of the machine sending the email).
:authentication – One of :plain, :login or :cram_md5. Should be omitted if the server does not require authentication. Also omit :username and :password options if you omit this parameter.
:username and :password – Mail account login credentials. Required if :authentication is set.

to test ActionMailer I used a private smtp server but it’s possible to use the smtp server of your email providere such as GMail (on the net there’s a lot of tutorials; e.g. try this one: http://guides.rubyonrails.org/action_mailer_basics.html#action-mailer-configuration-for-gmail).

How the registration process works
After the filling of the login form the system send to the user an email with an activation code.

Clicking on the link written in the email the activation process will be completed. This will be confirmed via email and the user will be redirected on the login page.

You can download the source developed till now clicking here.
In the next step we will see how to create pages accessible only to logged in users.


Learning Rails – Step 2

Hi all,
in this second step we’ll define the layout of the site and the controller to manage the informative pages.
First of all define the application layout:

I defined a simple layout with an header, a footer and a central area.
Into the header there will be the navigation bar. Colors and fonts are defined in a css file.

The public pages of the site will be managed by a controller. To create the ‘pages’ controller we can use the ‘generators’ window in RadRails.

The controller will have an action (method) for each page it has to manage: home, support, about.
The rake command also generates the necessary views to manage the 3 pages.

Filling the 3 views with appropriate html code we can obtain the below result.

You can download the source developed till now clicking here.
In the next step we will deal the user management.


Learning Rails – Step 1

Hi all,
some info before to start: my development environment is on a Linux machine and I use Aptana RadRails as IDE and MySql as database.

I thought to divide the project in four areas:

  1. default pages: home, about, support, login
  2. user registration and management
  3. contacts management
  4. lists management

Each area will be developed step by step.

First of all we must create a new Rails project: menu File->New->Rails project.

Then fill the Project name field with “EmailMkt”, check “Generate…skeleton” checkbox and select Mysql.

Now click “Finish” and RadRails will generate the application skeleton.

Now we have to modify the content of database.yml file. In this file there are 3 sections: development, test, production.
In each one of these sections we must change the database name and insert the correct username and password to access to MySql.

Now we must create the database. In RadRails you can do this or typing the “rake db:create:all” command in the Rails shell console or using Rake Task window or clicking the right mouse button and using the menu.

Ok, now we are ready to see if the application works: menu Run ->Run As -> Rails Application.

Wow! It works.

That’s all for now.


Learning Rails

Hi all,
I’m trying to learn Ruby on Rails and to do this I read a couple of books (Agile Web Development with Rails Second Edition, Simply Rails 2 by Patrick Lorenz), tutorials and saw LearningRails screencasts.

In spite of my effort my proficiency of Rails is still basic so I decided to improve it building a real web site and to share my code in this blog. In this way I hope to learn, also with your help (comments/suggestions), Rails in depth.

I’ll try to build an “Email Marketing Web SIte”: my inspiration is the MailChimp website, a professional and well done website.
Obviously my website will not be a replica of MailChimp nor a professional website: I only hope to examine and develop the main aspects of email marketing.

That’s all for now.
Stay tuned.


Reblog this post [with Zemanta]

Google Chrome OS Event

See the webcast.
Below an excerpt video


Samsung Launches Open Mobile Platform: Bada

Samsung Electronics Co. Ltd., a leading mobile phone provider, today announced the launch of its own open mobile platform, Samsung bada [bada] in December. This new addition to Samsung’s mobile ecosystem enables developers to create applications for millions of new Samsung mobile phones, and consumers to enjoy a fun and diverse mobile experience.

In order to build a rich smartphone experience accessible to a wider range of consumers across the world, Samsung brings bada, a new platform with a variety of mobile applications and content.

The name ‘bada’, which means ‘ocean’ in Korean, was chosen to convey the limitless variety of potential applications which can be created using the new platform.

Read on Bada blog

Reblog this post [with Zemanta]

The Ruby way

HI all,
I’m embarking on the Ruby way! Stay tuned.


Reblog this post [with Zemanta]