Articles

21. Contact Us Feature using Rails 2.0

This screencast uses the Simply Rich Authenticator app and builds the contact us feature using RESTful concepts. You can checkout the code from the Simply Rich Authenticator Google code website.

Correction: the index action is not required in the ContactsController.rb. Also for some reason the validation is not being triggered. If you find out the reason please let me know.

Refactoring: We are not alone!

http://refactormycode.com
Read this blog, it will make you smile!

I did some testing on the refactorings suggested in:
http://refactormycode.com/codes/2-ruby-simple-loop

testing.rb

def prof(t = 1, output = :puts)
starting_time = Time.now
t.times { yield }
dlta = (Time.now - starting_time).to_f/t
case output
when :ret

Why I love Ruby on Rails and what should be said on it's performance , part 1


In less than a week, you can establish a working model for your final product.

It is, however, very unwise to consider this is the end of the process.

Ruby on Rails allows ultra-fast development but all this comes in exchange to performance and efficiency.

Don't overestimate the power of versions

I've long been impressed and puzzled by the power of big version numbers. To open source projects like Ruby on Rails, it's such a divorced measure of quality or features that I feel we need to take it's importance down a few notches.

First of all, nothing magical happens when a certain revision of the code base is blessed with a release. It's simply the decision that what we have now should have a label. So when edge revision 8441 is given the alias of Rails 2.0.2, it's just that, an alias.

20. Extended RESTful Authentication Rails 2.0 App

This is a mini Rails app that uses RESTful authentication and Acts As State Machine with the following features:

  1.  Signup
  2.  Account Activation
  3.  Login / Logout
  4.  Forgot Password
  5.  Reset Password
  6.  Change Password 

The code is available from Google Code

P.S: The file size issue has been resolved.

19. AWDR Depot App using Rails 2.0 version

This screencast has upgraded the depot app found in Task A : Product Maintenance chapter of Agile Web Development with Rails book to Rails 2.0 version. Follow the steps in this screencast to get your feet wet with Rails 2.0 features. This is aimed at beginners who have no background in Rails.

The code is not available from this site. Please purchase the book from pragmatic programmer's website to get access to the code.

 Based on the Depot application developed in Agile Web Development with Rails

 

18. How to develop Plugins in Rails - Part 4

In the screencast on Include Vs Extend we have already seen how to mix in methods from a module so that they become available as class methods.

Apple Leopard REXML Bug

Just in case any of you wonder why when you use REXML’s write method on ruby 1.8.6 (2007-09-24 patchlevel 111) [universal-darwin9.0] and possibly other versions, you get errors, it’s a bug in Apple’s REXML library.

17. Rolling with Ruby on Rails Revised - Rails 2.0

Onlamp.com article now is upgraded to use the Rails 2.0 features. You will see the new features in action.

Mongrel: A recipe for Success, part 1

Take two different good things and combine them together.

Examples:

Wii - Ninetendo's winning game console

Nintendo took two simple technologies:

  1. The Wiimote (http://www.x-arcade.com/newsletter/Wii%20Dupe.shtml)

Rails Reminder: DATE_FORMATS | Rails Fire

Rails Reminder: DATE_FORMATS

Send to friend

A friend of mine recently asked me about adding time formats to Rails apps. It’s not completely intuitive on how to add new "default" symbols for date and time formats or to get a list of the built in ones. The API has the built-in lists of constants under DATE_FORMATS but it’s a bit difficult to read on that page. Here’s a link to the current stable version of the Rails time formats: rails/activesupport/lib/active_support/core_ext/time/conversions.rb. In order to add new ones you use the ruby strftime function.

ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS.merge!({
:quick => "%m %d, %Y at %I:%M %p",
:end_date => "%B %d, %Y"
})
 
ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!({
:job_list => "%B %d, %Y"
})

This lets you do something like <%= model.created_at.to_s(:quick) %> in your code.
And here’s the strftime options from the cheat page as a refresher:

%a - The abbreviated weekday name (``Sun'')
%A - The full weekday name (``Sunday'')
%b - The abbreviated month name (``Jan'')
%B - The full month name (``January'')
%c - The preferred local date and time representation
%d - Day of the month (01..31)
%e - Day of the month without leading zeroes (1..31)
%H - Hour of the day, 24-hour clock (00..23)
%I - Hour of the day, 12-hour clock (01..12)
%j - Day of the year (001..366)
%k - Hour of the day, 24-hour clock w/o leading zeroes ( 0..23)
%l - Hour of the day, 12-hour clock w/o leading zeroes ( 1..12)
%m - Month of the year (01..12)
%M - Minute of the hour (00..59)
%p - Meridian indicator (``AM'' or ``PM'')
%P - Meridian indicator (``am'' or ``pm'')
%S - Second of the minute (00..60)
%U - Week number of the current year,
starting with the first Sunday as the first
day of the first week (00..53)
%W - Week number of the current year,
starting with the first Monday as the first
day of the first week (00..53)
%w - Day of the week (Sunday is 0, 0..6)
%x - Preferred representation for the date alone, no time
%X - Preferred representation for the time alone, no date
%y - Year without a century (00..99)
%Y - Year with century
%Z - Time zone name
%z - Time zone expressed as a UTC offset (``-04:00'')
%% - Literal ``%'' character
 
t = Time.now
t.strftime("Printed on %m/%d/%Y") #=> "Printed on 04/09/2003"
t.strftime("at %I:%M%p") #=> "at 08:56AM"
t.strftime("%e %B, %Y") #=> "9 April, 2003"
t.strftime("%Y-%m-%dT%H:%M:%S") #=> "2003-04-09T08:56:07" (EN 28601)

The preferred method for doing this is to add these in an initializer in your app. Something along the lines of config/initializers/my_time_formats.rb.
Delicious Digg This Post Facebook Reddit This Post

No related posts.

Images: