ruby

Parsing latitude and longitude with Ruby

Hi! I need to parse some user submitted strings containing latitudes and longitudes, under Ruby. The result should be given in a double Example: 08º 04' 49'' 09º 13' 12'' Result: 8.080278 9.22 I've looked to both Geokit and GeoRuby but haven't found a solution. Any hint? ...

Rendering Partial onclick in Rails

I am trying to render a partial onclick to save on page loading time. <ul id="pop_twitter"> <% @topic_count.each do |k,v| %> <% @k = k %> <!-- make a link that onclick renders a partial below --> <li><% link_to_remote k, ?????? %></li> <ul id="twitter_<%= k %>" style="display:none;"> <!-- where the partial shou...

Testing with sanitize

I have this in my application_helper.rb: def bbcode(text) # Code snippets text.gsub!(/\[code=?["']?(.*?)["']?\](.*?)\[\/code\]/mis) { CodeRay.scan($2.strip, $1.to_sym).div(:line_numbers => :table)} text = sanitize(text, :tags => %w(span div table tr td br pre tt), :attributes => %w(id class style)) # Gist embedding text.gsub!(...

How to create a delete link for a related object in Ruby on Rails?

So let's say I have Posts and Comments and the url for show is /posts/1/comments/1. I want to create a link to delete that comment in the comments controller destroy method. How do I do that? ...

Install macruby to specific directory?

Normally macruby wants to install to /usr/local via 'rake install' I want it in another location. How do I do this? ...

Why can't Shoes::Setup#gem find my gem?

Despite reading what has been written on this here and here and here, I still can't get these lines to work for me: Shoes.setup do gem 'statemachine' end require 'rubygems' require 'statemachine' I have run "sudo gem install statemachine" successfully and copied the gem by hand to ~/.shoes/ to no avail so far. I am using ruby 1.8 ...

Apache2 is changing my content type for a Ruby cgi script

I have a ruby cgi script which writes it output like this: cgi.out("Cache-Control" => "no-cache, must-revalidate", "type" => "text/html", "charset" => "UTF-8") { template.result(binding) } Unfortunately, when I view the headers from cURL, I see the following: < HTTP/1.1 200 OK < Date: Sun, 23 Aug 2009 09:48...

Parsing Custom Tags with Ruby

I am trying to do pretty much the same thing as here, but in ruby: http://stackoverflow.com/questions/1201778/parsing-custom-tags-with-php ...

more succinct ruby regex

Is there are more succinct or Rubyesque way of writing this: if ( variable =~ /regex1/ || variable =~ /regex2/ || variable =~ /regex3/ ... ) end Namely, I'm hoping for something shorter, like: if ( variable =~ /regex1/,/regex2/,/regex3/ ) which I realize is not valid Ruby code, but figuring someone may know a more clever trick. ...

Ruby alternative for Lucene

Hi, I have heard about Lucene a lot, that it's one of the best search engine library in JAVA, is there any similar(as powerful) library for Ruby. ...

How would I invoke a rake script inside my rails application?

I want to execute a rake script from within a model. Beside calling it via backtick, is there anyway to include the rake library and call Rake::Task['some_task'].invoke. ...

libxml-ruby parsing HELP...

Alright, switching from working Hpricot to Libxml-ruby due to speed and well the disappearance of _why, looked at Nokogiri for a second but decided to look at Libxml-ruby for speed and longevity. I must be missing something basic but what im trying to do isn't working, here's my XML string file =<<XML <?xml version="1.0" encoding="utf-8...

What are the benefits/limitations of MacRuby and has anyone used it to program for iPhone?

I keep running across references to MacRuby and was wondering if any of you have used it for iPhone/Objective C programming. The MacRuby website says, "the goal of MacRuby to enable the creation of full-fledged Mac OS X applications which do not sacrifice performance in order to enjoy the benefits of using Ruby." So, my question is: wh...

How can I resize and watermark images in Ruby/Rails?

I am looking for gems that will allow me to resize and watermark uploaded images. I see a lot of posts on ImageScience and Mini-Magick but nothing that recent. I am looking for any experiences that will help me make a decision. ...

How do I enter a string of 2 or more words in a Ruby word array shortcut?

I'm aware of the Ruby word array: a = %w( stackoverflow serverfault superuser) How can I use the above to display a list where each item can have 2 or more words, for instance: a = ['stack overflow', 'server fault', 'super user'] ...

What is the best way to test authlogic-open-id with cucumber and webrat?

I've been having trouble using cucumber and webrat to test authlogic-openid authentication in a rails app. Following Ryan Bates's excellent screencast I was able to install authlogic with the open-id plugin. OpenID works when I login using the browser but so far I've been unable to test the app using cucumber and webrat. I've tried usin...

Where have the countries moved in Rails 2.3.3

Where has the COUNTRIES constant moved to, this used to work: >> ActionView::Helpers::FormOptionsHelper::COUNTRIES NameError: uninitialized constant ActionView::Helpers::FormOptionsHelper::COUNTRIES from /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.3/lib/active_support/dependencies.rb:440:in `load_missing_constant' from...

Floating point calculations with latitudes and longitudes of varying precisions

Background: I receive a long and lat as parameters to a web service. They are typically up to 6 decimal places. When a new request is received, I calculate the distance between the last recorded loc and the long/lat in the params of the request. If the distance is greater than a certain threshold of miles apart, I update the current loc....

Not including field names in validation error messages

If I have the following validation: validates_inclusion_of :dob, :in => Date.new(1900)..Time.now.years_ago(18).to_date, :message => "You must be 18 or older to register" The actual message on the site that shows up is: "Dob You must be 18 or older to register" Is there any way not to include the column name at the beginning of the m...

Good framework for Ruby web development.

Basically I am java developer and exploring ruby and ruby related framework right now. I am mostly working on web based projects. I had heard about RoR and Merb for web development in ruby. I am looking for good tutorial/books for Merb. ...