Ruby On Rails, Design, Simplicity, Web 2.0, Ajax, Mac and Tons of Pizza.

Apr 14

Rails 3, third beta release

Posted by Sandro Paganotti in Ruby on Rails - no comments digg this add to delicious

On the way to the first RC1 the core team relased today a new beta release due to the extraction of some features into plugins, let have a look to them in detail:

Rails Verification:

Rails verification bring into Rails some of the logic taken from the programming by contract paradigm; using this plugin you can define some constraint that need to be matched in order to call the requested action. This statement is implemented at class level as follow:


verify :params => "need_to_be_admin", :only => :update_post, 
   :redirect_to => { :action => "not_enough_privilegies" }

In this example a user is redirected to the ‘not_enough_privilegies’ action if he tries to access to the ‘update_post’ action withouth a parameter ‘need_to_be_admin’ setted. Note that, because they’re working only at controller-level, these prerequisites are not business rules. They do not examine the content of the session or the parameters.

Dynamic form:

This plugin only incapsulate some helpers methods that already belongs to Rails in previous versions of the framework; these methods refer to the creation of forms and the display of the model’s error messages.

Apr 02

Discover Gem Bundler

Posted by Sandro Paganotti in Ruby on Rails - no comments digg this add to delicious

I’m experimenting some features from Bundler, the new standard gem for calculating gem dependencies. Bundler works out of the box with Rails 3.0 but can also be implemented into Ruby projects without much effort.

All you have to do is install bundler with the command:

gem install bundler

Then you may create your Gemfile in your project root directory specifing wich gems you need; there is no DSL, just pure Ruby code with some nice helpers:


source "http://rubygems.org" 
gem "nokogiri" 

If you call ‘bundle install’ from command line now, all the missing gem specified in the Gemfile are installed (and compiled) automatically.

To benefit from these gems within your code you need to put on top of your .rb file the following lines:


require "rubygems" 
require "bundler" 
Bundler.setup

# now you can require all the gems specified in your Gemfile
require "nokogiri" 

And that’s it.

Dec 19

Streamlined, a new fork for Rails 3.0

Posted by Sandro Paganotti in News - no comments digg this add to delicious

In the last few days I managed to start porting the really well made Streamlined framework for Rails 3.0. This decision came after I discovered that the original plugin creators ceased its development . The code is freely available on github as a fork of the original project and at the moment is not fully tested nor fully functional except for its basic functionalities such as CRUD methods, search and exports. I’ll continue to work on this porting in order to re-implement all the features of the original version and hopefully to start developing new features and refactoring its codebase in order to met the new Rails 3.0 conventions.

Oct 29

Startup School 2009

Posted by Sandro Paganotti in Events - no comments digg this add to delicious

This day I had the pleasure to attend the 2009 edition of Y-Combinator’s Startup School 2009 helded at Berkley university, California. When I read the schedule of the event I stood impressed by the names of the speakers in particular I was curious to hear Mark Zuckerberg , the creator of Facebook, and Jason Fried, from 37 Signals. The event begun with a very entertaning presentation from Paul Graham focused on determing what are the key factors of a successful startup and, more generally, what really means be a startup founder. Then it was the turn of Greg McAdoo from Sequoia Capital who gave us advices on how and when a startup need to do fund-raising.

Jason Fried tryed in his speech to demiystify some of the common sentences related to a startup business; in his opinion you don’t need to search an initial investment to start a company; that’s because if you begun with money your first thought are on how spend it (employees, fornitures, ...); but if you don’t have money you focus only on how to make money.

Next went Evan Williams and Biz Stone, founders of twitter; their interview was full of funny anecdotes and tips; one over all: In the beginning of Twitter someone said ‘twitter is fun but it’s not useful’. Ev dryly remarked: ‘so is ice cream’.

After lunch the conference continued with an interview with Mark Zuckerberg, founder of Facebook, and ended up with a party helded within the Y combinator offices !

Sep 18

Mapping ROR, ROW and WhoDoes users....?

Posted by Annalisa Afeltra in Got Things Done - Ruby on Rails - Whodo.es - no comments digg this add to delicious

We thought it would be interesting to know where about our railsonwave.com and whodoe.es users are in the world…

So if you use Whodoe.es, read our blog railsonwave.com, you are a user of Ruby on Rails or a Web 2.0 designer, please add where you are located on the shared google map here, just your name/nickname and the area you are in, it does not have to be the exact address:


View Where is ROW and WhoDoes users….? in a larger map

Aug 28

Tools we need...

Posted by Annalisa Afeltra in Ruby on Rails - Web 2.0 - Whodo.es - no comments digg this add to delicious

When we look for a successful project management tool, what are the important aspects that we need to look for:

Share

  • Upload files and share them with your team
  • Tasks that need to be completed to reach deadlines
  • Share ideas and comments on tasks
  • Share e-mails with project e-mailer, keeping all e-mails archived

Collaborate

  • Collaborate with team members even from other networks
  • Teams collaborate with managers
  • Fast plan your tasks and milestones with Fastplan

Manage

  • Manage your tasks and milestones for a project
  • Manage your team members and what needs to be completed to reach deadlines
  • Keep Clients are satisfied by managing your teams and completing projects successfully

WhoDoes helps you: share, collaborate and manage your projects and team members. Simple and easy-to-use, quick registration.

Jun 19

Time driven crawling with Tarantula

Posted by Sandro Paganotti in Ruby on Rails - no comments digg this add to delicious

We are using Tarantula as an additional form of testing within our last project, Tarantula is called during a cruise control task to ensure that the application works also with realistic data (taken from the production database during the night).

The main problem we found in this approach was how to stop the crawler before it finish to load all the possible links collected during the session. This was critical for us ‘cause the web application currently handles thousands of elements and we could not wait hours.

So we chose to patch Tarantula in order to:
  • let the spider follow links in a random order
  • stop the spider after a configurable period of time (eg: 10 min)

Here’s the crawler.rb you’ll need to put under ‘lib/relevance/tarantula/’ in order to obtain this effect, then you can change two instance_variables: test_max_time_links and test_max_time_forms in order to choose how many minutes the spider will spend on these elements.

In the next days we’ll fork the Tarantula projects in order to better share this new behavior.

May 29

Upgrading your Rails app from Rails 2.1 to Rails 2.3....

Posted by Annalisa Afeltra in Ruby on Rails - 1 comment digg this add to delicious

If you still have some of your rails applications in Rails 2.1, here is how to start migrating to Rails 2.3 and take advantage of the new features….

Firstly, create a branch of your application

svn checkout path_of_application

Delete your current rails folder from vendor/rails from your branched application (if you had frozen rails into your app before) Install the Rails 2.3.2 framework and then freeze it into your application with these two commands:

sudo gem install rails --version 2.3.2
rake rails:freeze:gems

create a sample rails 2.3 application, then copy all the missing the config/initializers/ files from the test application to your branched application such as the session_store.rb, then copy the secret key from the environment.rb file into this file. This is to keep the environment.rb file small, braking parts into the config/initializers/ files

Remember to change your Rails version in your environment.rb file to Rails 2.3.2

rename your application.rb file to application_controller.rb or run

rails:update:application_controller

formatted urls

formatted_ * are no longer supported in the route helper due to using too much memory:

 formatted_users_path(:format => 'xml')  changed to users_path(:format => 'xml')

Internationalization

If you have used the globalization gem, it will no longer be compatible in Rails 2.3. Rails has now built in I18n Internationalization. (read more about internationalization)

The old way:

The new way:

In the config/locales/en.yml file we have the following:

The text is retrieved from these files, as well as if you have other languages such as italian, just create an it.yml file and replace the text with the translated text.

Hope this will help when you migrate to Rails 2.3….

May 20

I18n translate interface plugin...

Posted by Annalisa Afeltra in Ruby on Rails - no comments digg this add to delicious

I came across a really cool plugin that has a web interface for translating I18n texts.

Download the translate plugin from github written by Peter Marklund.

In the routes.rb file add the following:

now visit /translate and you will have an interface for translating text.

May 11

Euruko 2009 Summary

Posted by Sandro Paganotti in Ruby on Rails - 1 comment digg this add to delicious

Euroko’s 2009 is over and in these few lines I’ll try to summarize two days full of sessions, laughs and Ruby. Everything started with Matz’s opening speech which focuses on ‘Things we got’ explaining why Ruby’s got all the features a good language need (starting from the name), what are the next steps in the core development and why we don’t need to rush in the future.

During the day I found two very interesting speeches: one from Javier Ramirez that told us about Gosu, an enjoyable and pretty powerful gaming framework suitable for Ruby which can also be combined with Chipmunk (a physics engine) in order to obtain awesome effects and collisions.

Then I stumbled upon Cory Forsyth and his talk about Image Manipulation with Ruby that focuses on how to obtain three kind of quite advanced effects: photo-mosaic, seam carving and face detection using Ruby, Rmagick and some other cool libraries. On Cory Forsyth github page is also possible to appreciate some very well made examples about these techniques.

The day ends up (at least for me ‘cause I know some guys went partying somewhere) with a very nice stand up dinner made with delicious catalan ‘Jamon y Queso’ .

Sunday comes with an exceptional list of talks that impressed me much, starting from Adhearsion: a framework crafted to help people deploy applications that need to interact with Asterisk servers. The presentation was really cool and comprised a live coding demo which showed us how to write simple voice-enabled applications (with menus and digit recognition). After a short coffee break we met Adam Blum and Rhodes, a framework that let you create mobile applications for almost any existing smartphone using Ruby as coding language and HTML for creating views.

Then it was the turn of Pablo Formoso Estrada; his talk focused on Archaeopteryx which make the whole conference dance and clap their hands at the rhythm of a Ruby-driven runtime midi generator at which Pablo made adjustment just like a dj does with disks. Aslak Hellesøy then performed a good presentation explaining us what is Cucumber (a tool that helps creating semantic and readable tests written in human language) and showing us its latest features.

The last cool speech of the day was helded by Tomasz Stachewicz and focused on RuDy , a tool that lets you create Ruby extensions in D. The whole presentation was made to look like Antonietti’s much discussed ‘Perfoming like a Pr0n star’ but with ‘rock’ instead of ‘porn’, the result was very hilarious and it’s definitively worth a look.

And.. that’s it! Hope you enjoyed this summary and… see you next year in Krakovia!

ps: pictures of the event can be found at Euruko 2009 flickr photostream

Apr 22

Selenium and CruiseControl.rb

Posted by Sandro Paganotti in Ruby on Rails - no comments digg this add to delicious

Within the project we’re developing we found ourselves pretty attracted from the features offered by Selenium so we started to use its beautiful IDE to create behavioral tests that try to ensure our quality requirements.

But soon we discovered that manually aggregating and running these tests often lead to problems: first of all you don’t really have the same data on your developer instance each time you run Selenium so it happens that a particular business object is no more present or has been already, let’s say, processed and that means failure.

So we decide to move all the test we created to our CruiseControl.rb instance. To do that we followed these steps:

  • Create a Selenium startup script by following this good post from Mohammed Morsi;
  • Save your Selenium IDE tests as Unit Test File (File > Export Test Case As.. > Ruby) and copy them under your application tests/unit directory;
  • Put this piece of code within your ‘custom_cc.rake’ file

      begin
        puts "="*10 + "SELENIUM TESTS" + "="*10
        Kernel.system "ruby","script/server","-d","-e","development","-p","3000" 
        CruiseControl::invoke_rake_task 'test:units'
      rescue => e
        @test_errors << e
      end
        Kernel.system "killall","ruby" 
      end

That’s all! Hope you’ll find it useful !

Apr 08

How to retrieve find options from named scopes

Posted by Sandro Paganotti in no comments digg this add to delicious

Hi, It’s been a while since my last post, I apologize but I have been really busy with coding and testing (Cucumber is awesome!) for a quite important project. Within these days I came across this interesting trick that lets me discover how to return a ready-for-find options hash from a named_scope and also from an association.

So, let’s take this (simple) named scope for example:

named_scope :name, lambda do |query|
    firstname, lastname = query.split(" ")
    {:conditions=>{:firstname =>firstname, :lastname => lastname}}
end

By calling the method ‘proxy_options’ after the scope you’ll be able to retrieve the generated options Hash:


User.name(“Sandro Paganotti”).proxy_options 
#  {:conditions=>{:firstname=>”Sandro”, :lastname=>”Paganotti”}}
If you need to obtain the same result from an association you can use the method ‘construct_scope’ as follows

User.first.comments.send(:construct_scope)[:find]
# {:limit=>nil, :readonly=>false, :order=>nil, :include=>nil, :conditions=>”`comments`.user_id = 1”}

Sandro

Apr 03

Rails 1.2.3 to Rails 2.3

Posted by Annalisa Afeltra in Ruby on Rails - Whodo.es - no comments digg this add to delicious

As I mentioned last week, I am busy doing an upgrade of WhoDo.es from Rails 1.2.2 to Rails 2.3 and it is slowly sowly coming together, still have to do a lot of modifications for internationalization.

In my search for any help, I came across a very good step-by-step guide from Peter Marklund that might help someone if they might have a similar quest!

Hope it might be useful for someone else. Please follow the link here

Mar 27

Migrating WhoDo.es...

Posted by Annalisa Afeltra in Ruby on Rails - Whodo.es - no comments digg this add to delicious

I am currently working on Migrating WhoDo.es from Rails 1.2.2 to Rails 2.3.

My first steps were to migrate from Rails 1.2.2 to Rails 2.0 and no real big issues were faced, I only had to make sure that the gems that we were using were compatible with Rails 2.0.

Some of the following configurations had to be done:

  • Updated environments.rb with RAILS_GEM_VERSION = ‘2.0.2’
  • run rake rails:update:configs to update your config/boot.rb file from your current rails install.
  • In my config/environment/development.rb commenting out the following :
  •    #config.action_view.cache_template_extensions = false
    
  • Since they removed pagination from the new version, I had to install the will_paginate plugin.

My next biggest challenge is to migrate to Rails 2.3. Some more serious changes will need to be made, such as:

Keep an eye on this blog, any discoveries that I might come across I will be posting here…

Feb 27

iPhone on Rails

Posted by Giuseppe Arici in Ruby on Rails - 1 comment digg this add to delicious

Introduction to ObjectiveResource, the open source framework that connects the iPhone to the Ruby on Rails application

ObjectiveResource is a library that is written in Objective-C by YFactorial the purpose is to facilitate the integration between Ruby on Rails applications and programs for the iPhone.

As declared from the developers, the project starts from the idea to carry the potential of the module ActiveResource of Rails onto the iPhone .

The library supplies a system that is able to serialize the objects from and to web services RESTful standard of Rails (through XML o JSON) and makes the complexity requested transparent to invoke such as services from any programming language used on the iPhone.

Even if the library was recently released and is still under continues development, it is evident that the effort done by the developers in search of covering the functionality of ActiveResource and in the supply of an interface utilized along side fully conforms to the subsystem of Cocoa used as the management of the persistence of data, better known as Core Data as complete as possible in the world.

On the website dedicated to ObjectiveResource an introductive guide is available, quite useful just to give you an idea. It is also possible to download a project example that explains how simple and quick it is to use.

ObjectiveResource adds some methods to the class NSObject through the category NSObject(ObjectiveResource), in such a way that each instance of the Objective-C class can act from remote resource.

The name of the class and the name of the property must coincide with those from the remote resources of the Rails application. Given that the id is a reserved word in Objective-C, the property id of a Rails resource is mapped in Objective-C on a property, which name is composed from name of the class followed by suffix Id (like this for the class Dog such a property will be dogId)

The following code shows a Dog class that maps the correspondent Rails resource:


@interface Dog : NSObject {
 NSString *name;
 NSString *dogId;
}
@property (non-atomic , retain) NSString *name;
// map the property "id" of Rails
@property (non-atomic , retain) NSString *dogId; 
@end

To use the library it is necessary for us to put certain parameters in the ObjectiveResourceConfig class:


//Set the Rails website. The last slash is mandatory.
[ObjectiveResourceConfig setSite:@"http://localhost:3000/"];

//Set the username and password requested to connect to the Rails site
[ObjectiveResourceConfig setUser:@"remoteResourceUserName"];
[ObjectiveResourceConfig setPassword:@"remoteResourcePassword"];

//Set the protocol to use for remote communication(XML o JSON)
[ObjectiveResourceConfig setResponseType:XmlResponse];//il default
[ObjectiveResourceConfig setResponseType:JSONResponse];

All the CRUD operations are supported.


//Create
Dog *dog = [[[Dog alloc] init] autorelease];
dog.name = @"Pluto";
[dog saveRemote];

//Read
NSArray *dogs = [Dog findAllRemote];
dog = [Dog findRemote:dog.dogId];

//Update
dog.name = @"Bobby";
[dog updateRemote];

//Delete
[dog destroyRemote];

Other than ObjectiveResource, connected resources are also supported.

For example to find all the dogs that belongs to one person, you only need to add the following method for the Dog class:



+ (NSArray *)findAllForPersonWithId:(NSString *)personId {
 //using the generation method of the URL of ObjectiveResource to
 //construct the path nested.

 //http://localhost:3000/persons/:person_id/dogs.xml
 NSString *dogPersonPath = [NSString stringWithFormat:@"%@%@/%@/%@%@",
 [self getRemoteSite],
 [Person getRemoteCollectionName],
 personId,
 [self getRemoteCollectionName],
 [self getRemoteProtocolExtension]];

 Response *res = [Connection get:dogPersonPath withUser:[[self class] getUser] 
 andPassword:[[self class] getPassword]];
 return [self allFromXMLData:res.body];
}

The non CRUD custom actions are also supported. This is how you implement a method pet in the class Dog, that points to the URL http://localhost:3000/dogs/1/pet.xml:


- (void) pet {
 //Construct the path to the custom action pet
 NSString *petPath = [NSString stringWithFormat:@"%@%@/%@/pet%@",
 [Dog getRemoteSite],
 [Dog getRemoteCollectionName],
 dogId,
 [Dog getRemoteProtocolExtension]];

 //Send the request
 Response *res = [Connection get:petPath withUser:[[self class] getUser] 
 andPassword:[[self class] getPassword]];
 //Modify the property with the values restored from the server
 [self setProperties:[[Dog fromXMLData:res.body] properties];
}

@interface Dog : NSObject {
 NSString *name;
 NSString *dogId;
}
@property (nonatomic , retain) NSString *name;
@property (nonatomic , retain) NSString *dogId;
@end

#import "ObjectiveResourceConfig.h" 
[ObjectiveResourceConfig setSite:@"http://localhost:3000"];
NSArray *dogs = [Dog findAllRemote];

To complete this example, the developers have made a short screencast available on vimeo and have announced that the next tutorial published is on Pragmatic Programmers:.


Getting Started with Objective Resource from Josh Vickery on Vimeo.

Although some applications already exist that uses ObjectiveResource, as they indicate on the project website, the library still has enough margins for improvement. An idea could be to implement an automatic system generation of class files, that maps the resources of the Rails application.

You can create a script in Ruby that is able to reduce the property such as classes navigating the website, or better, using the Rails API directly.

The opinion of ObjectiveResource can only be positive: good idea, good projecting and careful implementation. Welcoming instruments that facilitate integration between the world of web and mobile devices such as iPhone. The opportunity that this library offers are interesting and many. Think of a possible example to simply develop functional applications for the iPhone, that makes it possible directly in real-time on the terminal of the user an altogether well-defined and limited to updated data (for example earnings of the quotations, on the variation of prices, on the unsold goods, ...) without having to develop the mobile version of the whole application.

At the end of this library it allows you to quickly develop with Ruby on Rails to the flexibility of the utilization of the iPhone: agility to the nth power!

Categories:

Tags:

Powered by Mephisto, Valid XHTML 1.1, Valid CSS - Supported by Wave Factory