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

May 06

WhoDoes 2.0 amazing groupware features

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

WhoDoes 2.0 is almost ready to go, but in the meantime I’d like to show you one of most interesting features we have introduced with this wonderful new version: groupware.

Now you can let other people look for you inside the WhoDoes user’s directory and allow them to make you part of their team. This is actually a real innovative feature in project management tools where you can now staff your team in seconds.

To enable other people to find you easily, you’ll have to check your settings inside the Settings tab of WhoDoes 2.0:

You can easily decide to keep your identity hidden or simply let people that share your email domain find and staff you automatically or set it that all users using WhoDoes invite you inside their projects.

May 05

Your task list in WhoDoes 2.0

Posted by Massimo Sgrelli in Ruby on Rails - Whodo.es - 2 comments digg this add to delicious

As you probably already know, we will release a completely renewed version of our project management tool in a few days. It’s named WhoDoes 2.0 and could dramatically make project organization easier in your company, in your team or simply in your daily life.

One of the new features WhoDoes 2.0 introduces is the ability to group all the tasks in a project by team member, independently from the milestones through which the tasks are bound together.

It’s easier to understand how useful it is, by observing this screenshot:

Stay tuned to learn more about this revolutionary tool.

Apr 30

Tasking with WhoDoes 2.0

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

Tasking items has never been so easy and simple with WhoDoes 2.0

How it is done…

The Task List gives you a clear indication of the workload for each team member, all tasks assigned to team members appear below their names and closed tasks are shown with the number of tasks that are closed.

WhoDoes 2.0 has taken working on paper and implementing it into the application. The shortcut add new task link enables you, just as in jotting down a “To-Do” list, to add new tasks unassigned or assigned to team members quickly and effortlessly.

With the simple drag and drop functionality, tasks that have not yet been assigned can be passed to team members by simply dragging the task to the name of the team member.

Any documents related to the tasks can be uploaded in the Documents uploaded section. Shared documents for the task are stored in a central point for team members to retrieve.

The project manager is kept up to date with the progress of the project and the number of hours that have been dedicated to each task. This is done with the easy-to-use hour uploading system within the task view, when the task has been updated the team is informed with an e-mail keeping everyone up to date.

Apr 29

Introduction to WhoDoes 2.0

Posted by Sandro Paganotti in News - Ruby on Rails - Whodo.es - 2 comments digg this add to delicious

Upcoming WhoDoes 2.0 is improved with more intuitive and easy-to-use features.

What’s new?

WhoDoes 2.0 makes it possible to start managing a project in a just few minutes, even more efficiently. Using just one of the new features Fast Planning, assigning tasks to team members, defining due dates, implementing task priorities and keeping your project’s progress under control is done simply and easily with WhoDoes 2.0

A new and innovative idea of sharing documents and e-mails has been built into WhoDoes 2.0, lost documents and e-mails will no longer be a problem. Team members will be kept up to date with WhoDoes’ new advanced centralized document and e-mail repository system which contains all the material that is related to the project with a new Project e-mail functionality.

Limited resources for a project is something in the past, WhoDoes 2.0 introduces network Teamwork. This will enable you to invite people to your team who are part of the WhoDoes network and have chosen to be visible. Finding resources is easier and simple. Not only can you find people to assign to your project with the WhoDoes network but you don’t need to re-invite users that already have a WhoDoes account, they can simply be added as a team member.

WhoDoes 2.0 has managed to integrate instruments into an online application making collaboration between team members and sharing of documents more efficient and easy for projects managed within the same office or projects with team members dispersed all over the world.

Apr 23

Playing with methods

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

I’ve recently bought a copy of The Ruby Way and I’m getting deeper and deeper into the most hidden and powerful Ruby features.

Yesterday I attempted for the first time to play with instance methods and I’m going to share what I discovered with you.

To start I want to remind you one of the most known Ruby introspection method:


 "ciao".methods
=> ["send", "%", "index", "collect", "[]=", "inspect", ... ]

by calling ‘methods’ on an object you get an array containing the name of all the methods that you can invoke on it (this include both its methods and the ones inherited from parent classes). But let’s go further: you can actually store a reference of one of these methods in a variable.


txt = "ciao" 
len = txt.method(:length)
len.call
=> 4

Now ‘len’ points to the method ‘length’ of the variable ‘txt’ (which is an istance of a String), so if we try to modify ‘txt’ then also ‘len’ change its result according to the changes:


txt << " a tutti" 
len.call
=> 12

But we can do more, by calling ‘unbind’ on ‘len’ you can separate the method ‘len’ is pointing at (i.e.: length) from the istance at which you get it (i.e.: txt), getting the vanilla ‘length’ method that you can next ‘bind’ to a new variable.


len_unbinded = len.unbind

new_txt = "haloa!" 
new_len = len_unbinded.bind(new_txt)
new_len.call
=> 6

That’s really impressive! And can turn pretty useful if you need to move a singleton method from one instance to another. There are more interesting features related to the Method class that can be found on the Method class RDoc, so if you are interested in this topic, or just curious, please have a look.

Apr 15

Create getter and setter on a valorized variable

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

I noticed that none of the attr_* (attr_reader, attr_accessor and attr_writer) has the capability to let you assign a value to the variable you’re creating.

This can be solved using the Class constructor method but it can lead you to define the initialize function just to make these assignements.

So I created an attr_with_value method that can be added to the Object class in order to make it avaiable to all the Classes and that can let you use the following sintax:


class Printer
  attr_with_value :pippo, 5
  attr_with_value :printer, Proc.new{|a| p "saying: #{a}" }
end

pr = Printer.new
pr.printer.call("hello!")
# "saying: hello!" 
p pr.pippo
# 5

pr.printer = Proc.new{|a| p "whispering #{a}"}
pr.printer.call("hello!")
# "whispering hello!" 

In the following snippet you can find the method:


class Object
  def self.attr_with_value(name,value)

    class_eval <<-EOS

      define_method(name.to_s) do      
        @#{name}_starter.nil? ? value : @#{name} 
      end

      define_method(name.to_s+"=") do |val|
        @#{name}_starter = true; @#{name} = val
      end

    EOS

  end  
end

I’m looking for a way to improve it (in particular I’m trying to find a clever way to handle the initial assignment), so every suggestion is welcome!

Mar 29

Matz's speech from Euruko 2008

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

I’m writting this post from Prague’s Euruko 2008 Ruby conference. The conference is taking place inside the city university and it is organized by Czech and Slovak Ruby User Group.

This morning we have attended to Matz’s speech titled ‘The Past, The Presen and The Future of Ruby’. Matz did a great comparison between all the current Ruby interpreters, JRuby, YARV, Rubinius. In particoular YARV impressed me much because, as explained by its author, Sasada Koichi, is up to 20x faster than the original Ruby interpreter!

Next Matz talk about some of the new Ruby 1.9 features, as enumerator chain:


            ary.map.with_index{|x,i|
                ...
            }

and a cool way to interact with enumerators out of a block:


    e1= [1,2,3,4]
    e2=[10,11,4]

    loop {
        p e1.next+e2.next
    }  
    #=>11,13,7

The last part of the speech was about Ruby 2.0, Matz sad that the keyword for this new release is scalability. Last but not least Matz talk about a new pre and post method hooks that will be implemented in Ruby 2.0 giving us more control on our functions (and maybe lead us to a design by contract paradigm in Ruby).

Mar 21

Ruby Pocket Session #3 - Callbacks

Posted by Massimo Sgrelli in Ruby on Rails - no comments digg this add to delicious

Active Records is the standard way that Rails provides to let your source code interact with databases. Active Records make available some standard callback functions to interact with their core tasks. Through callbacks you can intercept actions on databases, to perform some extra code before and after those actions. I found this topics interesting while refreshing my Ruby basics on the Ruby Pocket Reference and then I decided to go deeper through “Pro ActiveRecord – Databases with Ruby and Rails” (Amazon). I discovered this book some months ago reading Ruby Inside blog by Peter Cooper.

There are 2 ways to add a callback to your code:

  • overwriting the method
  • using macros

The best way to go through this, is using macros because of an inheritance hierarchy issue.

I’ll show a small example. Let’s suppose we have to define a Party and Customer model classes and we want to write a log when they have saved on the database:

Defining a callback using overwriting


class Party < ActiveRecord::Base
  def after_save
    writelog_party_saved
  end
end

class Customer < Party
  def after_save 
    writelog_customer_saved
  end
end

Defining a callback using macro


class Party < ActiveRecord::Base
  after_save :writelog_party_saved
end

class Customer < Party
  after_save :writelog_customer_saved
end

Using macros you preserve the inheritance chain of calls. So in the first case when you save a Customer record, no Party log is written. In the second case both callbacks are called, so the program writes a log for the Party record and one for the Customer record.

Mar 17

Observers: observing when changes have been made...

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

I wanted to find a solution that only sends an email to notify when a change has been made to the page. I came across the Observer. It works great when you need to compare if the value have been changed from before the save button to after.

This is how it works:

In the controller, add the following at the top of the page:


observer :mail_observer

and in the model, add the following to get the changed attributes:


attr_accessor :changed_attributes

Create a new model:

mail_observer.rb

Your mail_observer should look similar to this, I call two callback methods before_save and after_save:


class MailObserver < ActiveRecord::Observer
  #observe and the name of your model
  observe Task 

  def before_save(model)

   #Place the old values into a hash table only if it is not a new record being inserted
    old_attr = Hash.new
    if !model.new_record?
      old_model = model.class.find(model.id)
      old_attr = old_model.attributes
    end

    tmp_diff = Hash.new

    #delete the values in the hash table where the values have not changed, leaving you with the changed values
    model.attributes.delete_if do |key,value|
      old_attr[key] == value    
    end.keys.each do |k|
      tmp_diff[k] = old_attr[k]
    end

    model.changed_attributes = tmp_diff   
  end

In the after_save function I check which values have changed by !model.changed_attributes[‘resource_name’].nil?, for example if a task that has been assigned to a person, is changed to another person, an email is sent to alert the new person that a task has been assigned to them.


  #the after save function you can check which values have been changed and do something for it, depending on what has changed

  def after_save(model)      
      #task resource_name
      if !model.changed_attributes['resource_name'].nil?
         #send an email to the person that has been assigned this new task
         puts 'the owner of this task is has been changed.' 
      end
 end

This could be a good example to check when changes have been made to a page and to alert the changes that have been made.

Mar 05

RVG and SVuGy: create vector graphic with Ruby

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

Today we’re going to discover two ways to create vectorial graphic with Ruby;

RVG

The first way is called RVG and it’s part of the well-known Rmagick library. With RVG you can create custom shapes and then render them to images. Here there is a simple example (taken from the RMagic docs and modified a bit):


require 'rvg/rvg'

target = Magick::RVG.new.viewbox(0,0,200,200) do |targ|
    targ.g.styles(:stroke_width=>20, :stroke=>'#ff5600', :fill=>'#abd600') do |grp|
        grp.circle(90, 100, 100)
        grp.circle(60, 100, 100)
        grp.circle(30, 100, 100)
    end
end

rvg = Magick::RVG.new(258, 100) do |canvas|
    canvas.use(target, 0, 0, 100, 100)
    canvas.use(target, 100, 16.6667, 66.7, 66.7)
    canvas.use(target, 166.6667, 25, 50, 50)
    canvas.use(target, 216.6667, 30, 40, 40)
end

rvg.draw.write('nested_rvg.gif')

And this is its output:

SvuGy

This library acts in a very similar way with the small but noticeable difference that its output is not an image but a pure .svg file. Here is the code to product the same sample as above ( I know, it is not so DRY but i didn’t find smarter ways to do this, in part due to a lack of documentation):



require 'SVuGy'

drawing1 = SVuGy::Document.new(530, 200) do

    tri = group.style(:stroke_width=>20, :stroke=>'#ff5600', :fill=>'#abd600'){
      el2 = ellipse(100, 100, 90, 90)
      el1 = ellipse(100, 100, 60, 60)
      el0 = ellipse(100, 100, 30, 30)
    }

    tri2 = group.style(:stroke_width=>20, :stroke=>'#ff5600', :fill=>'#abd600').translate(200,30).scale(0.66){
      el2 = ellipse(100, 100, 90, 90)
      el1 = ellipse(100, 100, 60, 60)
      el0 = ellipse(100, 100, 30, 30)
    }

    tri3 = group.style(:stroke_width=>20, :stroke=>'#ff5600', :fill=>'#abd600').translate(330,50).scale(0.5){
      el2 = ellipse(100, 100, 90, 90)
      el1 = ellipse(100, 100, 60, 60)
      el0 = ellipse(100, 100, 30, 30)
    }

    tri4 = group.style(:stroke_width=>20, :stroke=>'#ff5600', :fill=>'#abd600').translate(430,60).scale(0.4){
      el2 = ellipse(100, 100, 90, 90)
      el1 = ellipse(100, 100, 60, 60)
      el0 = ellipse(100, 100, 30, 30)
    }

end

print drawing1.to_svg

And here you can admire the generated SVG (download the file):

Considerations

Now that I found out this library I’m thinking about an hypothetic world where these two libraries works with the same syntax letting you generate SVG if the browser support this format and otherwise printing a simple image. Another big improvement could be create a SVG to RVG parser, by this way you can import complex SVGs generated with WYSIWYG programs and then add to them dynamic functionalities.

Mar 04

Ruby Pocket Session #2 - Duck typing

Posted by Massimo Sgrelli in Ruby on Rails - no comments digg this add to delicious

I have to admit it. I have never heard of duck typing, probably because I read “Ruby Programming” to quickly. “Duck typing” is the way Ruby treats variable types. I mean, Ruby is a dynamic language and so variables don’t have explicit type assignments or declarations. Ruby has dynamic typing, but why has it been called duck typing?

Well, Dave Thomas puts it in this way: if it walks like a duck and quacks like a duck, then I would call it a duck.

BTW you can read more about the original meaning of this concept on Wikipedia searching for duck test .

Duck Typing is a distinctive feature of dynamic languages like Lisp, Perl, Ruby, Python, Caml and Groovy and it’s part of the “funky stuff” that characterized those wonderful languages. Some people are worried about this feature, because they think that late-binding could be dangerous: you can pass an object to a method not actually “quacking like a duck” and you wouldn’t know since runtime, when this line of code would be executed.

I don’t think this is a real issue. The fact is that using Duck Typing saves you a lot of time with a very low risk of delivering buggy code because of this feature. The truth is that normally people release buggy code because of their poor testing, and it doesn’t depend on static or dynamic binding.

I love this concept. Thanks Ruby. Thanks Dave

(Ref. See Ruby Pocket Reference p. 11)

Mar 03

Ruby Pocket Session # 1 - instance_methods

Posted by Massimo Sgrelli in Ruby on Rails - 3 comments digg this add to delicious

Ruby is a wonderful object oriented programming language. The root class is Object which provides a set of very useful methods among which one called instance_methods. It returns an array with all the public methods of the class or the public methods of the module. Retuning an array you can apply normal array’s operators like this:


class Dog
  attr :bark, true
end

irb> Dog.instance_methods - Object.instance_methods
irb> ["bark", "bark="]

(Ref. See Ruby Pocket Reference p. 38)
Feb 29

Ruby Pocket Sessions

Posted by Massimo Sgrelli in Ruby on Rails - 2 comments digg this add to delicious

I have been a full time software developer for many years and I love to keep myself up to date with programming languages and technology in general. Of course in the last two years Ruby and Ruby on Rails have been my main interests. My time is often spread over a thousand activities at the same time, and I love that. But as soon as I have spare time, I like dedicating some hours to coding. I’m not actually a Ruby expert like the well known star DHH or Jamis Buck or Peter Cooper, but I am for sure a Ruby and Ruby on Rails enthusiast and a true believer.

If you aren’t a full time developer all the time when you start coding you need a quick refresh of the basics. That’s why Ruby Pocket Reference is so precious to me and I thought of sharing this refreshing sessions with all you Ruby new comers, I just highlighted on this blog small Ruby characteristics that I found while reading this guide or browsing the Net. Nothing complicated, only a small quick review moment.

So keep in touch and looking forward to my Ruby Pocket Sessions.

Feb 21

RailsConf 2008 speeches recommendation system

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

Trying to find a way to code an application that uses the recommendation library I wrote about a couple of weeks ago, I started thinking on how could be improved a conference’s schedule and I came out with this little speech recommendation system.

What is it ?

It’s a little web application that uses data collected from users choiches to suggest you a bunch of speeches that you may find interesting. For each speech a recommendation index is calculated using Pearson Distance algorithm and an appropriate message is given to the user based on that index.

How it Works ?

The application first asks you for a few speeches you are sure to attend to, then it calculates the Pearson distance between yours and other users choiches and basing on that index it finds which speeches may be interesting for you.

Screenshot and application’s link

Here is a screenshot of the application, I used YUI base css pack to speed up the developing process while keeping the layout clean and cross browser.


The ‘choose a few speeches you are sure to attend’ phase


The ‘a bunch of speeches you may find useful’ phase

Now, what next ?

Well, now it’s time to try out the conference speeches recommendation system; when the application will start to collect a considerable amount of data I’ll publish some statistics about the most wanted speech !

Try WhichSpeech?, RailsConf2008 recommendation system!

Disclaimer

What I created is intended as an exercise about recommendation algorithms and it works only by estimating your preferences based upon other users choices. It does not aim to show that some speeches are better that others.

Feb 07

Active Scaffold Address Book

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

I created an address book just to get an idea of how the active_scaffold plugin works, it’s pretty neat! It saves you a lot of time setting up the base of your web application.

I followed the tutorial that I found on Active scaffold

Lets look at my example:

Firstly create a simple address book project with two models, contact and client and generate their corresponding controllers. Therefore the address book will contain a list of contacts with their clients.

In the client model, add belongs_to :contact and in the contact model has_many :clients.

After setting up the small application install the active scaffold plugin with the following:


./script/plugin install http://activescaffold.googlecode.com/svn/tags/active_scaffold

Create a new layout called admin:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
  <title>Address Book</title>
      <%= javascript_include_tag :defaults %>
    <%= active_scaffold_includes %>
</head>
<body>

<p style="color: green"><%= flash[:notice] %></p>

<%= yield  %>

</body>
</html>

All the magic happens in the controllers, in the contacts_controller add the following:


  layout "admin" 

  active_scaffold :contact do |config|
    config.label = "Contacts" 
    config.columns = [:name, :surname, :tel, :email]
    list.columns.exclude :email 
    list.sorting = {:name => 'ASC'}
    columns[:tel].label = "Phone #" 
    columns[:tel].description = "(Format: ###-###-####)" 
  end


and in the clients_controller add:


  layout 'admin'

  active_scaffold :client do |config|
    config.columns = [:contact, :name, :surname, :tel, :email]
    columns[:name].label = "Name" 
    columns[:surname].label ="Surname" 
    columns[:tel].label = "Phone" 
    columns[:email].label = "@E-mail" 
  end

run the application and see how your application has become active in just a few simple steps….

Categories:

Tags:

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