Posts Tagged ‘Programming’
Remaking MBNet at Codebits
December 5th, 2009 • 4 comments Blog, Events, Programming
Tags: codebits, mbnet, Programming, rails, ruby
We’re participating once again on Codebits this year with the help of Bauke Schildt on the design.
We’ve decided to try something diferent and create a proof-of-concept remake of the MBNet platform to show how it can be improved and adapted for todays time.

Upload files using Paperclip on Ruby on Rails
March 19th, 2009 • Comments Off Blog, Programming
Tags: file upload, paperclip, Programming, rails, ruby, tutorial
Paperclip is an awesome plugin to handle file uploads in Ruby on Rails. I’ve been using in a couple of projects lately and I thought I’d talk a bit about it.
First of all, you need to install the plugin on your project by doing:
script/plugin install git://github.com/thoughtbot/paperclip.git
from your project main directory. After this, usage is very simple.
Let’s imagine I have a user model and I want to have a avatar attribute to include a picture of the user and let’s say we want that avatar to be resized to 3 different sizes (120×120, 48×48 and 26×26). Paperclip does this using ImageMagick.
We’re first going to create a migration to hold all this information:
class AddAttachmentsAvatarToUser < ActiveRecord::Migration
def self.up
add_column :users, :avatar_file_name, :string
add_column :users, :avatar_content_type, :string
add_column :users, :avatar_file_size, :integer
add_column :users, :avatar_updated_at, :datetime
end
def self.down
remove_column :users, :avatar_updated_at
remove_column :users, :avatar_file_name
remove_column :users, :avatar_content_type
remove_column :users, :avatar_file_size
end
end
Then we define the attribute in the model:
class User < ActiveRecord::Base
has_attached_file :avatar, :styles => { :large => "120x120>", :medium => "48x48>", :thumb => "26x26>" }
end
Here’s an example on how your form should be:
<% form_for :user, @user, :url => user_path, :html => { :multipart => true } do |form| %>
<%= form.file_field :avatar %>
<% end %>
Your controller doesn’t have to do anything specific to handle the avatar, just save the user as usual.
def create
@user = User.create( params[:user] )
end
And finally, if you want to show the avatar in your view, here’s some examples:
<%= image_tag @user.avatar.url %>
<%= image_tag @user.avatar.url(:medium) %>
<%= image_tag @user.avatar.url(:thumb) %>
That wasn’t very difficult. There’s some advance stuff you can do with Paperclip, like upload via a URL or upload your files to Amazon’s S3 or define post processing operations on your files.
So get creative and use it in your projects. :)
Update: The WebFellas have a very deep and interesting article about Paperclip, check it out.
Performance on Rails Barcamp pt 08
September 6th, 2008 • Comments Off Blog
Tags: barcamp08, barcamppt, Programming, rails
I just finished my presentation on Barcamp pt 08 which is held again in Coimbra. Although I was a bit nervous I think it went ok.

The topic I choose was Performance on Ruby on Rails where I talked about the different issues surrounding getting the most performance out of your Ruby applications.
I spoke about all the types of Caching, including the recent changes in Rails 2.1 and other tips for optimization which could be abstracted to other languages.
I think I managed to explain the different ways the Rails framework has to help optimize your web applications. You can see the slides from Performance on Rails on SlideShare.
I’m hoping forward for the other sessions, there’s some very interesting topics like scrumm, mysql optimization and others. See you there.
Update: I’ve uploaded my photos from the event to my Flickr profile.
Opera Web Standards Curriculum
August 7th, 2008 • Comments Off Blog, Web, design
Tags: campaigns, Programming, Web, web standards
Opera published the Web Standards Curriculum, a series of articles which were released in association with the Yahoo! Developer Network, the goal is to:
teach you standards-based web development, including HTML, CSS, design principles and background theory, and JavaScript basics.
I find the initiative very positive, there’s already 23 articles and 30 more are coming until the end of the year. Very nice!

Another worthwhile campaign is “Save the Developers” which focuses on assisting and encouraging users in upgrading their Internet Explorer 6 web browser. On the long run it will also help developers who have to spend time making hacks and tweaks for designs to work properly in IE 6 (damn you!).
So upgrade now to a decent browser and help us save the developers. :)







