ruby

Is it possible to run a Ruby project via Rake?

I've got a Ruby project started with NetBeans, so the Rake file has been generated. Is there a way that I can run the project over the command line? It runs fine when I use F6 through NetBeans, as does my automated test suite with Alt+F6. I'm essentially looking for something like... $ rake run Does this exist? ...

How to measure the size of a Ruby object?

Hi, I'm having Memcache problems and I was wondering what is the best way to know how big the objects I create are. The only solution I have is to put them into Memcache which display their size in bytes (by the way, can I customize Memcache's output? I want readable kilobytes…). Thank you, Kevin ...

sinatra app doesn't start on run

I'm on Ubuntu 10.10/Ruby 1.9.2 Whatever I do, I can't get a sinatra app to start on my local machine. hello.rb: require 'sinatra' get '/' do "Hello World!" end "$ ruby hello.rb" and "$ ruby -rubygems hello.rb" both result in a new prompt with no action taken. Any tips or pointers? ...

Ruby on Rails - Clean up url parameters

I have a Rails app set up so that when a user uploads an image, it is sent directly to Amazon's S3. I have to specify a redirect address in the form code. After the image is finished uploading, Amazon redirects the user to www.redirect_address.com/?bucket=[BUCKET]&key=[KEY]&etag=[ETAG] I need the bucket and key info to process the image...

Question about inheritance in Ruby.

I've been attempting to teach myself Ruby over the past while and I've been trying to get something like the following to work but I'm getting the following error... file.rb:44:infunc': undefined local variable or method number' #<classname:0xb75d7840 @array=[]> (NameError) The code that's giving me this error is... class A def ...

Rails RSpec Tests for a has_many :through Relationship

I'm new to testing and rails but i'm trying to get my TDD process down properly. I was wondering if you use any sort of paradigm for testing has_many :through relationships? (or just has_many in general i suppose). For example, i find that in my model specs i'm definitely writing simple tests to check both ends of a relationship for r...

Heroku app fails to start - `require': no such file to load -- sinatratestapp (LoadError)

I'm trying to get my Heroku app to run using the bamboo-mri-1.9.2 stack. Of course it's running fine locally on Ruby 1.9.2. But when on production it crashes during the startup on executing config.ru which looks like this: require 'sinatratestapp' run Sinatra::Application My .gems file: sinatra --version '>= 1.0' And the applicatio...

How to make Ruby's Find.find follow symlinks?

I have a file hierarchy and some of the sub-directories are relative symlinks. I am using Ruby's Find.find to crawl through these dirs and find some specific files. However it's not looking into any directory which is a symlink (it follows files which are symlinks). Looking at the source code it seems the problem is because it's using F...

In Ruby / Rails, why "gem server" says haml depends on maruku and yard but "gem list" doesn't show these gems?

If I run gem server and go to localhost:8808, one of the entry is haml and it says it depends on maruku and yard haml 3.0.22 [rdoc] [www] - depends on maruku, yard. An elegant, structured XHTML/XML templating engine. Comes with Sass, a similar CSS templating engine. Executables are css2sass, haml, html2haml, sass, sass-convert. b...

How do I write methods that insert rspec examples?

In a bunch of rspec rails unit specifications I do something like: describe Foo do [:bar, :baz].each do |a| it "should have many #{a}" do Foo.should have_many(a) end end end For cleaner code I'd rather do something like: describe Foo do spec_has_many Foo, :bar, :baz end So how do I write a helper method like spe...

mocking in Ruby: mocks are sticking around between tests

I'm using RR as the mocking framework for a personal project of mine. I've been using it to mock the new method for some classes and when I run the tests they pass fine, but when I run ALL of the tests I run into a problem where it seems like the "new" methods are still returning the fake results, even when in a different test file. Is...

Rails 2.2.2 - Missing template error when trying to render a partial in a subdirectory

I'm getting the following error when Rails tries to render my layout located in app/views/layouts/application.html.erb: Missing template shared/_header.erb in view path /home/me/checkout/site/app/views: Extracted source (around line #11): 8: <body> 9: <div id="wrap"> 10: <div class="clear">...</div> 11: <%= render :partia...

simple jquery plugin to upload a file via jQuery (Ruby on Rails)

Hello, I'm looking for a simple jquery plugin to upload a file without FLASH. For Ruby on Rails. Single file upload progress bar indicator and all the bits have been uploaded. ...

sort by in Array ruby

I have array a = ["aaa", "bee", "cee", "dee"] I want have new array with sort as like: a = ["cee", "aaa", "dee", "bee"] Please help me. thanks. ...

Regex "\w" doesn't process utf-8 characters in Ruby 1.9.2

Regex \w doesn't match utf-8 characters in Ruby 1.9.2. Anybody faced same problem? Example: /[\w\s]+/u In my rails application.rb I've added config.encoding = "utf-8" ...

Order a collection as DESC

<%= render :partial => 'event', :collection => @events.sort_by(&:event_at)%> This code shows a collection ordered as ASC, but i want to order this collection as DESC. How can I achieve this? ...

install Ruby 1.8.6 with rvm in Mac OS X 10.6 Snow Leopard failed

I'm trying to learn Ruby on Rails and wanted to follow Apple's example: http://developer.apple.com/tools/developonrailsleopard.html It requires Ruby 1.8.6 and Rails 2.0.2 My machines is already updated to 1.9.1. I wanted to use rvm to install 1.8.6 but it failed during make with the following log: [2010-10-20 10:43:31] make eval.c: I...

What is wrong in this ruby statement?

I am trying to do something when I am connecting to my own server(local). I found request.env from the website, so I am using that array to compare my IPs. <% if request.env['HTTP_HOST']!="127.0.0.1" puts request.env['HTTP_HOST'] else puts "its Local!" end %> When I run above in rails3, I get nothing printed... I am new t...

using geokit or other ruby gem to calculate the center of a series of geo coordinates.

I've been using the geokit and geokit-rails gem for rails for awhile but one question I haven't found answered is how to find the calculated aggregate center for a collection of points. I know how to calculate the distance between two points, but not more than 2. My reason is, I have a series of points all in the same city... all thing...

What's the best way to connect to SQL Server from Ruby on OS X?

I need to let my Rails app connect to a MS SQL Server database and do a simple query to do a lookup. The main DB for the app is MySQL. It just needs to do this SQL Server thing on the side. What's the best way to do that? I could write an entirely separate app in Java that connects to the DB and dumps some XML data to the filesystem fo...