ruby

ruby double question mark

I came across this piece of ruby code: str[-1]==?? What is the double question mark all about? Never seen that before. ...

Is it possible to convert an HTML document to Excel with multiple Worksheets/tabs?

Hi there, I know we can send regular html files through the tubes and have the browser open them as Excel documents (you do that by changing http headers and the file name, then excel does the conversion). BUT, is it possible to get an HTML document show up in Excel with two Worksheets/Tabs? Here's what I thought might work, but didn't...

Why Observer pattern is much more complicated in C# than in Ruby?

I've read in "Design Patterns in Ruby" by Russ Olsen how Observer pattern can be implemented in Ruby. I've noticed that Ruby implementation of this pattern is much simpler than C# implementation, e.g. implementation shown in "Programming .NET 3.5" by Jesse Liberty and Alex Horovitz. So I've rewritten "Programming .NET 3.5" Observer ...

Simple but confusing Ruby string manipulation.

I am trying to convert a small bit of Ruby to PHP, and I have had success so far, except for this one line: string = string[16,string.length-16] I have tried these two things in PHP: $string = substr($string, 16, strlen($string) - 16); // and $string = substr($string, 16, strlen($string) - 32); But the problem is that I have no clu...

Why does Model.find behaviour in a deployed environment differ from that in a development enviroment?

Using Ruby on Rails combined with capistrano and git, I've run into an annoying problem.. I have a controller "people" with the index action that looks something like this: def index @people = Person.find( :conditions => params[:search] ) end There is a boolean "is_admin" column in the Person table. Assuming that some of the peopl...

How to read Perl DB_Files in Ruby

I'm migrating a Perl script to Ruby. The Perl script uses DB_File in DB_HASH mode. How do I read all the keys and values from such a file in Ruby? ...

Multiple forms for the same model in a single page

On the front page of my rap lyrics explanation site, there's a place where users can try explaining a challenging line: Here's the partial I use to generate this: <div class="stand_alone annotation" data-id="<%= annotation.id %>"> <%= song_link(annotation.song, :class => :title) %> <span class="needs_exegesis"><%= annotation.ref...

Flash not surviving a redirect in Facebook on a Rails application

I have the following two action methods: def index puts "==index== flash: #{flash.inspect}" end def create flash[:notice] = "Blah" puts "==create== flash: #{flash.inspect}" redirect_to(:action => :index) end index.fbml.erb contains this: <%= button_to_with_facebooker "Blah!", :action => :create %> The application is used t...

Default values for querystring parameters, the Ruby way?

What's the Ruby way to do this? if params[:month] @selected_month = params[:month].to_i else @selected_month = Time.now.month end ...

Hpricot error parsing special characters in URI

I'm working on a ruby script to grab historical stock prices from Yahoo, using Hpricot to parse the pages. This is mostly straighforward: the url is "http://finance.yahoo.com/q/hp?s=TickerSymbol" For example, to look up Google, I would use "http://finance.yahoo.com/q/hp?s=GOOG" Unfortunately, it breaks down when I'm looking up the price...

Ruby: What's the proper syntax for a boolean regex method?

What is the proper syntax for a method that checks a string for a pattern, and returns true or false if the regex matches? Basic idea: def has_regex?(string) pattern = /something/i return string =~ pattern end Use case: if has_regex?("something") # woohoo else # nothing found: panic! end ...

trouble installing ruby gem json on my mac

I get this warning when trying to install the json module via ruby gems. Any ideas? Mac-Mini poulh$ sudo gem install json Password: WARNING: File '/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8 /specifications/json-1.2.0.gemspec' does not evaluate to a gem specification ...

Learning 'advanced' ruby to contribute to rails?

What is the best place to learn 'advanced' Ruby so I can start contributing to Rails? Any other things I should read/know would be appreciated. Thanks. ...

Printing to screen in a rake task

I have a long running rake task. Every now and then I print an update to the screen to let me know how far along the task has come. puts "Almost there..." My problem is all the puts statements seem to buffer somewhere and won't print to the screen until after the task is complete. At which point, they will be printed all at once. Is ...

seeking syntax for date in where clause in Jet OLEDB

Hello, I have a problem of using the where clause for limiting dates I can't even get a simple statement like on "Feb 5 2010" to work, e.g., select * from LineItems where DueDate = 2/5/2010; I tried "2/5/2010" "2010/2/5" "2010-2-5" "2010-02-05" 2010-2-5 2010-02-05 ... but none worked. Does anyone have an idea what the proper format fo...

Best practice for handling two similar objects

Let's say I have two different controller/view sets that are basically identical. Business hours and Staff hours The first contains a business_id, the latter a staff_id. Otherwise they look the same. id, mon_start_time, mon_stop_time, tues_start_time, tues_stop_time, etc... 1) Is there a way I would use the same controller for these s...

Rails: How can I configure to routes.rb for /:id?

I am working on my personal site with RoR. I searched and read books. But I cannot figure out. How Can I configure routes.rb for xxxxx.com/:id? For example: twitpic.com's image url or short url is "http://twitpic.com/11u1cy". ...

Can prawn generate PDFs with links?

I need to embed a link into a generated pdf in a ruby on rails app. Is there a way to do this with prawn? Reading about this it turns out that prawn-format was the answer for awhile, but 0.7.x broke this. prawn-format uses the link_annotate(rect, options={}) function to create links. What options need to be passed into this to get it t...

Rails 'returning' method - One-liner to build Array from Multiple Arrays in Ruby?

How do I convert the following to a clear one-liner in ruby? def questions results = [] sections.each do |section| results = results.concat(Question.find_all_by_survey_section_id(section.id)) end results end I feel like I could use the &: (Symbol#to_proc) and returning methods in there somehow. ...

Getting the skype status of user in a rails application

I have a rails application in which user provides his skype address.I want to able to determine the skype status of the user(online or offline) when some one sees his profile. How can i do that in my application? Does any know of a ready to use gem/plugin? ...