Articles

Integrating Flickr into your rails website

In this post I’m going to show you how I created the little Flickr stream you can see running down the right hand edge of this site.

Step 1: Get a Flickr API key

Visit this page and follow the instructions to get a key and write it down somewhere safe. Of course you are going to need a Flickr account to do this as well!

rails gotchas: restful_authentication not 2.0 compliant?

restful_authentication[1] is a great plugin, but the standard svn version is showing it's age. It's a whole month or so out of date... which is, of course, an eternity in the fast-paced world of Rails.
Luckily it's actually just moved home. You can find the up-to-date version on github

[1] Formerly known as acts_as_authenticated

Save images from any URL

Save images from any URL

Note: it will works only OS –> WINDOWS and Browser –>  IE

1. install Ruby

2. Install watir gem – gem install watir

3. Look this code

Code:

require ‘watir’
include Watir
#browser = Watir::IE.new
browser=Watir::IE.new
browser.visible=true
browser.goto(’http://www.misipile.com/’)

idx = 0

Github Bookmarklet For User Pages

I have a confession to make. I use github all the time. In order to feed the addiction, I decided to logically awesomeize github’s user page. What ensued was a jQuery plugin/bookmarklet which enhances the github user page with repository sorting. And yes, my addiction has only gotten worse.

Test Drive

Copy the bookmarklet:

Original Author Name: 
Gabriel Horner

rails gotchas: HttpMock not enough variables

A quickie for my own remembrance. I'm currently setting up HttpMock to test ActiveResource. I'd set up a few extra "routes" for it to mock out and kept getting the error below:
NoMethodError: undefined method `size' for :not_found: Symbol
For the code line:
mock.get "/users/#{uid}.xml", {}, :not_found
The fix was pretty simple - I'd just accidentally missed out the "nil" for the body - ie it

Rails - Useful Plugins

In updating myself I found some really useful Rals plugins for my next project.

Hoptoad Notifier

FilterableEnumerable

My recent post on Enumerable#filter created a bit of discussion on RubyFlow, which led to a m

Twitter Gem Reborn with Fewer Features and 100% More OAuth

In which I show off the rewritten Twitter gem and an example app that takes advantage of it.

The Twitter gem is kind of my baby. It was pretty much the first gem I created and as such I care for it a little more. When I originally created it, I knew nothing. I sucked. Now over time, I suck less and Twitter’s addition of OAuth seemed like the perfect time to completely rewrite it. Yay for rewrites!

Passenger 2.1.3 packages for Ubuntu Hardy

Phusion Passenger 2.1.3 has been released and we’ve updated our Ubuntu packages as usual.  Instructions in the usual place on our wiki.

More on data driven design

It’s hilarious to listen to and read designers talking about how they think google design sucks.

For example, in this podcast they all agree at the end that, in their expert design opinions, google needs to add more padding and whitespace.

Articles | Rails Fire

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.

Cap 1.4.1? Go 1.4.2. Now. | Rails Fire

Cap 1.4.1? Go 1.4.2. Now.

Are you currently using Capistrano 1.4.1? If so, drop everything (I mean it, do this RIGHT NOW) and install Capistrano 1.4.2.

Why, you ask?

Capistrano 1.4.1 will work just fine, right up until you decide you want to experiment with Capistrano 2. When you do that, Cap 2.3+ will install net-ssh 2.x, which kills Capistrano 1.4.1 in all kinds of really obscure ways.

The good news is that Cap 1.4.2 is completely compatible with Cap 1.4.1. It adds no new features. The only “bug” it fixes is that if you ever install net-ssh 2.x, Cap 1.4.2 will still happily continue to work.

Ultimately, an upgrade to Cap 2 is recommended, but I understand it’s not feasible for everyone. So, if you’re one of those who can’t go cap2 yet, please please please PLEASE PLEASE FOR THE LOVE OF ALL THAT IS HOLY upgrade to Cap 1.4.2. It’ll make your life easier, and it’ll make my life easier (because I won’t have to keep troubleshooting the same issues over and over). Thanks!