Articles

Defining methods in Ruby

1 – Hashes in method calls

You must have seen this syntax in Rails a lot, for example when using this Paperclip plugin, you would put this in your model:

Using Java libraries from Clojure

After reading Scripting Java Libraries With Ruby on the Engine Yard

undefined-method-stringify-keys - Replace ` with

If you are getting an `undefined method stringify_keys! for String` it is because you're passing a String to an ActiveRecord method that requires a hash. The common way of encountering this is having a form like this:

<% form_for @message do |f| %>
<%= text_field_tag "message" %>
<%= f.submit %>
<% end %>

Ruby5: A Twice-Weekly 5 Minute Ruby News Podcast

ruby5-itunes-logo.pngRuby5 is a new twice weekly podcast dedicated to Ruby and Rails news. It's headed by Gregg Pollack (formerly of the RailsEnvy podcast which Jason Seifer has now taken over) and Nathan Bibler. They aim to cover several bits of Ruby and Rails news in five minutes.

Table Aliasing e Legacy Naming - creata

Supponiamo di avere il modello User nella nostra applicazione Rails; di default Rails suppone che ci sia una tabella chiamata “users”.

class User < ActiveRecord::Base
end

Sfortunatamente (nel nostro esempio), le informazioni degli user sono contenute in un legacy database su una tabella chiamata USER_DATA_TBL05 (brrr, che orrore). Non si può cambiare il nome della tabella per far felice Rails perchè il sistema legacy dell'azienda che usa quella tabella non funzionerebbe più.

Eager loading - creata

Limitare il numero di di query SQL è uno dei modi migliori per migliorare la performance di un'applicazione Rails, e l'eager loading è probabilmente il modo migliore per farlo.

Il problema

Supponiamo di trovarci nella seguente situazione molto comune: si ha bisogno di un'applicazione Rails con il model Person. Ogni persona ha più amici (has_many...friends). Cosa si deve fare per trovare gli amici di una persona?

Rails 2.3.4 is out, security vulnerabilities fixed

Rails 2.3.4 is out, just a few weeks after the 2.3.3. There are no new features, the reason for this quick release are the 2 vulnerabilities found in the Rails code (one is a possible XSS epxloit and the other is a cookie hack. The release notes state that over 100 small bugs were fixed as well.

Polymorphic Relationships - creata

Polymorphic Relationships

Le Polymorphic relationships permettono di avere un singolo modello associato a un numero arbitrario di altri modelli.

Esempio

Ad esempio, supponiamo di avere un database di contatti che utilizza due modelli, Person e Company. Entrambi Persons e companies hanno degli indirizzi che si vogliono conservare nel database, e si vuole poter interrogare tutti gli indirizzi in un colpo solo (tipo per una ricerca basata su un luogo).

Database Relationships

Con Ruby on Rails le relazioni tra le tabelle si dichiarano nel modello ActiveRecord. Con l'aiuto di Ruby on Rails, l'interprete Ruby usa quelle informazioni per interagire magicamente con record particolari.

Ci sono diverse opzioni per dichiarare le relazioni tra le quali:

Principi di base di Ruby on Rails

Principi di base di Ruby on Rails

Convenzioni piuttosto che configurazioni

Rails fornisce delle impostazioni predefinite per ogni aspetto riguardante lo sviluppo di un'applicazione web. Seguendo tali convenzioni puoi realizzare un'applicazione Rails, scrivendo molto meno codice rispetto a molti altri framework per applicativi web. Se hai bisogno di bypassare le convenzioni, con Rails puoi farlo ed è pure molto semplice.

Articles | Rails Fire

Articles

Ruby on Rails Tutorial PDF download now available

As some of you may already have seen on the recent Rails Inside post about Ruby on Rails Tutorial, the Ruby on Rails Tutorial book PDF is now available for download! It's still only chapters 1–4, of course, but I'll be keeping it in sync with the web version of the book from now on.

I have issues





Since we launched Issues so many months ago, many users have asked for a way to see all the issues spread across all their repos. We don’t have a page for this on GitHub yet, but the information is exposed via the API.

RailsTutorial.org: Michael Hartl's Awesome New Rails Tutorial

railstutorial.pngRailsTutorial.org, a.k.a.

GitHub Meetup SF #12

What you want another drinkup? Fine, but this is the last one for the year. Primarily because the next slated drinkup Thursday would fall on December 31st, and if you somehow dont know or perhaps are still under the respective drinking age in your country, everywhere is a drinkup that day.

How Phusion Built A More Efficient Ruby 1.8 Interpreter

ninh-bui.pngPhusion Passenger and Ruby Enterprise Edition developers Ninh "Hernandez" Bui and Hongli Lai travelled to San Francisco last week and gave a 35 minute Google Tech Talk called Building A More Efficient Ruby Interpreter.

No returns

Chris Wanstrath makes a good point about an ugly way to initialize a variable, but I don't agree that an explicit return is the best style to use.

The original ugly:

def logger
  unless @logger
    @logger = Logger.new(STDOUT)
    @logger.level = Logger::WARN
  end
  @logger
end

Chris' improvement:

def logger
  return @logger if defined? @logger
  @logger = Logger.new(STDOUT)
  @logger.level = Logger::WARN
  @logger
end

I prefer a functional style:

IRC channel for Rails Tutorial

Thanks to the efforts of Miles Forrest, the Ruby on Rails Tutorial project now has a dedicated IRC channel! Find it at #railstutorial on irc.freenode.net using your favorite IRC client or at http://webchat.freenode.net in your browser.

Ruby EventMachine: a short introduction

Introduction

Before answering what is EventMachine, first I will try to explain the problem that EventMachine solves.

A network server like http server or chat server usually works in a threaded model. What it means is that on a particular port, a process is listening for connections. When a client makes a connection then this process spawns a new thread and that thread is handed over the task of responding to that client. If server is getting too much traffic then the number of threads created by the main process goes up very quickly.

Your Pages Will Load Faster with Rails!

This article was originally included in the October issue of the Engine Yard Newsletter. To read more posts like this one, subscribe to the Engine Yard Newsletter.

In Inside Rails, Yehuda Katz, Rails expert and core team member, and Carl Lerche, Rails expert and full-time contributor, present expert advice and insight on the Rails platform and Rails development.

GitHub Rebase #32

Want to see your project on Rebase? Check out the howto! I also seem to be running short of interesting Git images as well. If you see any, and given they don’t contain Larry the Cable Guy, shoot me a message.

Keep digging deeper. | Rails Fire

Keep digging deeper.

The same thrill, the same awe and mystery, comes again and again when we look at any question deeply enough. With more knowledge comes a deeper, more wonderful mystery, luring one on to penetrate deeper still. Never concerned that the answer may prove disappointing, with pleasure and confidence we turn over each new stone to find unimagined strangeness leading on to more wonderful questions and mysteries -- certainly a grand adventure!

— Richard Feynman, 1955 address to the National Academy of Sciences (full text)

Images: