ruby

url encode equivalent in ruby on rails

Is there an equivalent to PHP's urlencode in Ruby on Rails 2.3.5? I googled it but all the answers seem to date back to before 2006 and seems dates. This is what I found. It seems a bit abnormal to call CGI::escape in a view. Is there an equivalent helper function? Thanks! ...

Is there a Passenger compatible implementation of taps for Ruby on Rails?

Does anybody know of a gem that provides taps-like functionality, that is compatible with Passenger (mod_rails)? When I try to use taps on a Ruby EE/Passenger setup, I receive the error: `detect_rack_handler': Server handler (thin,mongrel,webrick) not found. (RuntimeError) Although it's not specifically stated in the readme, I am ass...

What's wrong with my ruby gems setup?

I'm trying to run a ruby file which imports a gem. The ya2yaml gem is installed, yet somehow it is not found: $ cat delme.rb require 'rubygems' require 'ya2yaml' $ ruby delme.rb /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- ya2yaml (LoadError) from /Library/Ru...

hash of Array gives incorrect size results - Ruby

I am trying to insert a List in Hash.. However, hash[key].size is giving me invalid results. p = Hash.new p = {"a" => ["b","e"]} puts p["a"].size #prints 2 ----This is the Problem p["a"] << ["d", "f"] puts p["a"].size #prints 3 puts p["a"][1] #prints e puts p["a"][2] #prints df How, adding more lists increment the size only by one (wh...

Why doesn't this ruby code compare regex ?

if string == /\s{1,}/ or string == /\n{1,}/ puts "emptiness..." end ...

How to script elements embedded within an <iFrame> tag?

Hi, I am using Firefox and i have a page which has an <iframe> Tag. The contents embedded within this tag cannot be seen from normal "View Page source" option. So i installed Firebug plugin and i can get see the contents using Firebug. My issue is, i cannot script any of these elements using FireWatir. Anybody has any ideas how to do...

How out of date is the "blog tutorial" video on the ruby on rails website?

Hay, with the release of Ruby on Rails 3 soon, I thought I'd dive back into a bit of Ruby on Rails programming. I missed out version 2 of rails and had only previously been using 1.2 So i hopped on the video tutorial and worked through it. I just wanted to know how out of date is the video? Does all the theory in that video, and ways of...

Ruby: How to determine if file being read is binary or text

Hi, I am writing a program in Ruby which will search for strings in text files within a directory - similar to Grep. I don't want it to attempt to search in binary files but I can't find a way in Ruby to determine whether a file is binary or text. The program needs to work on both Windows and Linux. If anyone could point me in the ri...

Ruby IRC bot don't works.

require "socket" server = "irc.rizon.net" port = "6667" nick = "Ruby IRC Bot" channel = "#0x40" s = TCPSocket.open(server, port) s.print("USER Testing", 0) s.print("NICK #{nick}", 0) s.print("JOIN #{channel}", 0) This irc bot don't connect to the IRC server, What are i'm doing wrong? ...

Best functional approach to AND across a list

Suppose I have an array of values [a,b,c,d,...] and a function f(x,...) which returns true or false. [1,2,3,4].map {|x| f(x)} => [true true false true] First, what is the best way to collapse the resultant list into a true or false value (via AND)? Is there a function that would allow me to map: [true true false true] to: ((tr...

Ruby on Rails forms: missing template on submit

My controller has two methods: index and search. def index: renders the default view, index.html.erb, and displays a default map using YM4R/GM. def search: renders the default view using render index, but uses form input to display a custom map using YM4R/GM. The view, index.html.erb, contains a partial view, _form.html.erb, and the @...

Is there any way to keep all the tasks inside Rake in reenable mode?

I'd like to run tasks in a Rakefile multiple times. Is there a way to specify that, or do I need to .reenable them each time I want to invoke them? ...

"GMT" instead of "UTC" in Ruby 1.8

According to the Ruby docs for Time#zone: As of Ruby 1.8, returns "UTC" rather than "GMT" for UTC times. My OSX-using comrades see this behavior. On my Ubuntu 9.10 system, however, Ruby 1.8.7 seems to prefer the old "GMT" terminology: $ ruby --version ruby 1.8.7 (2009-06-12 patchlevel 174) [i486-linux] $ ruby -e 'puts Time.now.ut...

Appending to an existing string

To append to an existing string this is what I am doing. s = 'hello' s.gsub!(/$/, ' world'); Is there a better way to append to an existing string. Before someone suggests following answer lemme show that this one does not work s = 'hello' s.object_id s = s + ' world' s.object_id In the above case object_id will be different for ...

Ruby Variables Clarification

I see that Ruby has the following variables: - global variables (represented by $variable_name) - class variables (represented by @@variable_name) - instance variables (represented by @variable_name) and - local variables (represented by variable_name or _variable_name) Occasionally I see the following in the rails source code: class S...

Ruby Global Variables

In Ruby is there any method that lists all the global variables available at the point of inspection like $GLOBALS in php? ...

Ruby Class Constants

In Ruby we can find out the class methods by Class.methods, instance methods by Class.instance_method, is there any methods that lists all the constants defined in a class? ...

Ruby on Rails form_remote_tag missing template

I'm using form_remote_tag(:url => {:controller => "home", :action => "search"}, :update => "mydiv"). When I click submit on the form "mydiv" is populated with the error "Template is missing. Missing template home/search.erb in view path app/views". I've tried multiple render options in def search, but they all result in the same error...

Are there any good reference (open-source) Rails NoSQL apps?

I'm interested in seeing how using NoSQL would affect the architecture/design/code of a Rails application. Does anyone know of a good example of a open-source Rails app using NoSQL persistence? Thanks ...

Is there a Perl equivalent of the ruby koans project?

Is there a Perl equivalent to the ruby-koans project? When I was starting to learn ruby a few months ago I stumbled across ruby-koans and it was a huge help for learning the basics of the language. I now need to poke at some Perl code, and while I've hacked together a few Perl scripts in the past I've never really learned the language,...