ruby

Friendly Byte Formatting in Rails

I need to format an integer representation of bytes into something friendly, and I'm hoping that there's a utility function in Ruby or in Rails that will do that formatting for me (to perpetuate my laziness, of course.) I'm looking for something that would look like: format_bytes(1024) -> "1 KB" format_bytes(102400) -> "1 MB" L...

Rails plugin for API Key + Secret Key signing

Is there a Rails plugin or a rubygem that gives you a starting point for adding an api to your Rails app? We want to use the API Key/Secret Key model, the API should also be versionable. Is there something out there that will give us some, if not all of this? ...

What tools do you recommend to profile Rails apps?

I've been looking for profiling tools for Rails for a while. I'm currently playing and testing ruby-prof and railsbench, but I kinda frustrated with the amount of tweaking and mangling required to make then work. Althought I don't mind (much) the tweaking, I'd like to know if is there any other, more straight-forward and easy to use, to...

Can apache's ProxyRemote be used to proxy HTTPS requests to mongrel for processing?

So I have a custom proxy that is written in ruby using mongrel to handle some fairly complex caching logic. This works great for both http and ftp requests, however since mongrel is not designed to handle https requests, I wish to front the whole thing with apache and make use of the ProxyRemote command to pass through to mongrel for ht...

What is the best way to extend restful_authentication/AuthLogic to support lazy logins by an anonymous iPhone?

I'm building an iPhone application that talks to a Ruby on Rails backend. The Ruby on Rails application will also service web users. The restful_authentication plugin is an excellent way to provide quick and customizable user authentication. However, I would like users of the iPhone application to have an account created automatically by...

Ruby 1.8 and UTF-8 string case statment compare (Ruby on Rails 2.2)

Hello :) I have a rake task (in lib/tasks directory) that I run with cron on my shared web hosting. The problem is that I want to compare a UTF-8 string using case statment but my source code is not UTF-8 encoded. If I save source code as UTF-8 there is error when I try to start it :( What I have to do? May be read this strings from ...

Gettings started with Ruby on Rails 2.0 for Windows

So like many people, I'm excited about Ruby on Rails. Being a Windows user, I downloaded InstantRails, got it going, and followed along with the screencast on how to make a blog with RoR 2.0 in fifteen minutes. I used Notepad++ as my text editor, because that's what I've traditionally used for writing the PHP-based websites I've done in ...

Print Ruby object members

When I'm running a simple Ruby script, whats the easiest way to dump an object's fields to the console? I'm looking for something similar to PHP's print_r() that will work with arrays as well. ...

Rails ActiveSupport Time Parsing?

Rails' ActiveSupport module extends the builtin ruby Time class with a number of methods. Notably, there is the to_formatted_s method, which lets you write Time.now.to_formatted_s(:db) to get a string in Database format, rather than having to write ugly strftime format-strings everywhere. My question is, is there a way to go backwards?...

rake undefined exitstatus in nil:Nilclass

I am trying to run rake on a new machine (original machine works fine) . . after running my this i get an error saying . . rake aborted undefined method exitstatus for nil:nilClass any suggestions for how i could see whats going on here? ...

What are some good examples of Mixins and or Traits?

I was reading up on Ruby, and learned about its mixins pattern, but couldn't think of many useful mixin functionality (because I'm not used to thinking that way most likely). So I was wondering what would be good examples of useful Mixin functionality? Thanks Edit: A bit of background. I'm Coming from C++, and other Object languages, b...

Is there a way to run a view inside a partial

I know this is odd. but I can't figure other ways to do what I need. I have a controller: report and a view: report. Also I have a view that acts as a dashboard where I can see several zones (partials). I need to add this report view to my dashboard but don't know how. This report view utilizes complex logic from controller and displays ...

Organizing pictures (or any files)

This is a bit of a stretch, but I have an interesting (to me) programming (err... scripting? algorithmic? organizational?) problem. (I am tagging this in Ruby, because of my preference for Ruby for scripting.) Imagine you have 100 gigabytes of pictures floating around on multiple drives. There are likely a total of 25 gigabytes of uniqu...

Can I traverse symlinked directories in Ruby with a "**" glob?

In Ruby, Dir.glob("**/*.rb") (for instance) doesn't traverse symlinked directories. Is it possible to get the ** to traverse symlinks? I'm using two gems which find files this way, but I need them to see files within a symlinked directory. ...

What kind of ruby method call is Array(x)

What is the meaning, and where is the Ruby documentation for the syntax of: Array(phrases) which I found browsing the Rails source here: # File actionpack/lib/action_view/helpers/text_helper.rb, line 109 ... 119: match = Array(phrases).map { |p| Regexp.escape(p) }.join('|') I thought that Array.new would normally be used...

What is the best way to find and replace "!= null" code with andand?

I refactor my code and I am looking for a solution to grep my source files for something like if ( user && user.name && user.name.length() < 128 ) ... in order to replace it later with ruby's andand or groovy's ?. operator (safe navigation operator). ...

Rails form validation

I have a Rails app that lets a user construct a database query by filling out an extensive form. I wondered the best practice for checking form parameters in Rails. Previously, I have had my results method (the one to which the form submits) do the following: if params[:name] && !params[:name].blank? @name = params[:name] else fla...

constant values in Rails

I have some data that I want to store somewhere in my Rails app because I use it for generating form fields, checking a submitted form to ensure its values are valid, etc. Basically, I want the data in one location because I make use of it in several places. Previously, I was defining an initialize method in my controller and initializ...

How do I add a name.value to the header when generating a soap message from ruby with soap4r

I've created a driver from wsdl When I invoke my request, I would like the header to contain an element, i.e, I want to see something like the following: REPLACE_WITH_ACTUAL blah blah blah However, looking around, everyone talks about subclassing SOAP::Header::SimpleHandler and then injecting an instance into t...

How to know in Ruby if a file is completely downloaded

Our issue is that our project has files being downloaded using wget to the file system. We are using ruby to read the downloaded files for data. How is it possible to tell if the file is completely downloaded so we don't read a half complete file? ...