Help with Ruby on Rails?

If you come across something that stumps you with ruby or rails, or there is something that you don’t quite understand, let me know. I would love to help out with trying to solve your problem.

Also, if you have something you would like me to explain or create a “how-to” on, let me know about that too. Leave a comment here, or write me an email.
You can contact me at randy@freezzo.com

Rails Unit Test multi-array params

While writing some tests the other day, I came across a little bit of a stump. I have an action that required the use of a multi-dimensional param such as:

param[:user][:name]

This is exactly what I was doing, but you get the picture. I could have easily changed it to a single array, but that not the point. The solution in this example, would be to nest your hash in the test such as:

def test_should_do_something
  post :create, :some_object=>{
    :name=>'Bob'
  }, :user=>{ :name=>'Something' }
end

Full message for error_messages_for

I found this somewhere while looking around for the easiest way to provide my own full message for the rails error_messages_for output.

Basically what we are going to do here is provide a humanized string for a variable of the model, and when the error message is printed out, it will display that message. This give more control instead of just having “Email is required.”

class Person < ActiveRecord::Base
 
  HUMANIZED_ATTRIBUTES = {
    :name => "Please provide a name for this person.",
    :email => "You must specify an email address."
  }
 
  def self.human_attribute_name(attr)
    HUMANIZED_ATTRIBUTES[attr.to_sym] || super
  end
 
  validates_presence_of :name,  :message=>''
  validates_presence_of :email, :message=>''
 
end

Override default find conditions for model

Here is a little trick I use when I want to override a find method for a model, instead of adding the conditions option to my association. While I don’t think you should avoid using the conditions options in your associations, this will provide an alternative:

class ModelName < ActiveRecord::Base
  def self.find(*args)
    with_scope(:find=>{ :conditions=>LIMIT_CONDITION }) do
      super(*args)
    end
  end
end

Basically what is happening, is that you are overriding the default find function for a model, and wrapping its own find method with a with_scope call. So now everytime you call Model.find(:all) or whatever options you want, it will execute it under that scope, with the conditions you specify.

Ruby random number by day

This is a cool little snippet of code that will return a random number, that changes by day:

def random_by_day(max_value)
    srand Time.now.strftime("%m%d%Y").to_f
    rand(max_value)
end

YouTube’s MP4 Video Formats

Based on the recent update to YouTube and the ability to request an mp4 version of the videos on there server, I was able to add the ability on Jamzee to download an iTunes file that you can import into iTunes. Now you can create and listen to your YouTube playlist, created on Jamzee, right on iTunes.

While I am not here to share the process to retrieve these files, you can get some great information here:

http://googlesystem.blogspot.com/2008/04/download-youtube-videos-as-mp4-files.html 

I am still in the process to figure out a nice way to allow those Jamzee playlists to be exported to an iPod. If anyone has any ideas about that, I would love to listen!

Rails Log Analyzer (RAWK)

Came across a sweet rails log analyzer. Doesn’t require that you use syslog or anything like the other log parsers that are out there. This one will work right on your development or production log files. Its called RAWK and you can find it here:

http://rubyforge.org/frs/?group_id=2517&release_id=15246

Jamzee has been updated!

In the effort to make Jamzee more socialized, we brought in the lovdbyless framework to help create this. We have updated the website with the new design and are still working on flushing out any bugs with the code/design.

You now have the ability to create a profile, upload pictures, write blog posts, comment on other playlists and users, search members and playlists, and more!!!

Come check out the new Jamzee!

Jamzee

$1600 in 1 Month - Bux.to

Bux.to

So I will cut right to the chase.

A month ago I signed up at Bux.to. Its a website where you get paid to click links and they allow you to buy your own referrals. I invested $1100. At the end of the month I am now to $1600, and its growing everyday.

The other sweet thing about them is that you can get a prepaid mastercard that gets loaded right from your bux account balance, and I do infact have and activated the card. I cashed out and am awaiting the payment to the card.

There are numerous amounts of success stories of others being paid, and I have no doubt that they will pay me. I am just awaiting patiently.

You don’t however have to invest any money or just a little bit, but I highly recommend it as the turn around is better than any bank can give you. If you want to sign up, CLICK HERE.

Here is my current stats:

Your Statistics  
# of Website Visits

875

   
Your Referral Statistics  
# of Referrals (view)

1137

# of Referral Website Visits

127026

   
Additional Credit/Debit  
# of Credit/Debit (view)

0.24

   
Balance Information  
Account Balance (cashout)

$ 1,597.2500

Total Amount Paid

$ 0.0000

Top Notch Academic Systems

“Kelly” is at it again, and so is our hard working English system.

The following gem may be somewhat interpretable and I will do my best to give you the English version. If anyone knows this language, please, feel free to fill me in.

ne was wut web sit do you go to 2 bern cd’s?

Translated into english this means

Anyway. What website do you go to, to burn cd’s?