ruby

How do I render all Comments in a Rails view?

I am new to rails so go easy. I have created a blog. I have successfully implemented comments and attached them to each post. Now...I would like to display, in the sidebar, a list of the most recent comments from across all posts. I think there are two things involved here, an update to the comment_controller.rb, and then the call from t...

Sphinx delta indexing -- still necessary to rebuild the main index?

I've been reading up on the Sphinx search engine and the Thinking Sphinx gem. In the TS docs it says... Sphinx has one major limitation when compared to a lot of other search services: you cannot update the fields [of] a single document in an index, but have to re-process all the data for that index. If I understand correctly, that...

How do I compile Readline support into Ruby

My version of ruby was compiled with editline (on os x) and I miss the features of readline in irb. How do I recompile ruby with readline support? ...

Serialization problem in Rails

When we try to deserialize a Model from our database we always receive a YAML object. For that we added the following code in the environment.rb: YAML.add_domain_type("ActiveRecord,2007", "") do |type, val| klass = type.split(":").last.constantize YAML.object_maker(klass, val) end class ActiveRecord::Base def to_yaml_type "!A...

How do I split a URL into 2 parts in Ruby?

I have a ruby script that downloads URLs from an RSS server and then downloads the files at those URLs. I need to split the URL into 2 components like so - http://www.website.com/dir1/dir2/file.txt --> 'www.website.com' and 'dir1/dir2/file.txt' I'm struggling to come up with a way to do this. I've been playing with regular e...

Sound libraries for ruby

I'm looking for a ruby library that would let me read/write .wav (or another sound format, preferably loseless) files, and operate on waveform. ...

Model relation issue with Ruby on Rails

I have a few models: class StatsParent < ActiveRecord::Base class CourseStat < StatsParent class PlayerCourseStat < CourseStat I have the Course model set up as such: class Course < ActiveRecord::Base has_one :course_stat has_many :player_course_stats def update_stats(plyr_rnd) puts self.course_stat # this puts #<PlayerC...

How do I parse an encoded URI in Ruby?

I'm trying to parse a URI that has brackets - [ and ] - in it. I have tried to parse this directly with URI.parse but the brackets cause this to fail. I therefore tried to encode the URI with CGI::escape which takes care of the brackets but when I try to parse this encoded URI with URI.parse it doesn't seem to recognise it as a URI and p...

regular expression back referencing

why this snippet: 'He said "Hello"' =~ /(\w)\1/ matches "ll"? I thought that the \w part matches "H", and hence \1 refers to "H", thus nothing should be matched? but why this result? ...

Multilingual admin with Globalize2

I have a multilingual admin (for English and Portuguese) that needs to save data for both languages at the same time, like Description EN field and Description PT field in the same form. Globalize2 makes some magic and I don't know exactly how to save this. I'll post my controller action here, that obviously needs some refactoring. Than...

Ruby net-dns reverse lookups

I am trying to get reverse DNS lookups working with the net-dns gem for ruby. From the rdoc res = Net::DNS::Resolver.new ip = IPAddr.new("172.16.100.2") packet = res.search(ip) packet = res.search("192.168.10.254") should work but I'm getting ArgumentError: invalid address for the last two lines. This happens using a custom ge...

How to enable ruby methods visualizing in vim

Hi, a have googled the question, but found nothing - maybe I do not know how to define the search keywords properly in this case. I like to use folding in vim when I'm developing Ruby on Rails applications. And my foldcolumn is set to 4. But its visualizing of the start and the end of the ruby method is not so simple and obvious ("-" - ...

RSpec setup for an application that depends on an external database from another application.

I've had to add features to an application that depends on a database from another application. I've been able to set up a connection to this external database and pull data from it. However, I'm not sure how to get my main application to create a test database for this external application. It would be awesome if there some way to pul...

How to use group_by with fields_for in rails?

I have a model with many children (selections). I need to display the children using fields for but I really want to group them based on an attribute on each selection using group_by. Currently I am using accepts_nested_attributes_for :selections, :allow_destroy => true So my form looks a bit like this: <% form_for @match do |form|...

Why rubygame and gosu are slower than pure opengl ?

I'm looking for a good graphic framework to make a nice 2D game in Ruby. I made 3 very simple test to see which graphic Ruby framework is faster between Gosu and Rubygame. The test creates 1000 instances of a "Square" class that move and draw a red square by the simplest way using the framework's method. The 3rd test is the same thing bu...

Running out of socket connections with Net::HTTP

Hi, I have some fairly boiler-plate Ruby code (running on Linux) which sends a GET request to a server ... req = Net::HTTP::Get.new(path) req.content_type = 'text/plain; charset=utf-8' req.body = '' port = 443 res = Net::HTTP.new($host, port) res.use_ssl = true res.start do |http| t = Benchmark.measure do _return = http...

how to model this ruby structure in redis

hi, i'm thinking use redis (http://code.google.com/p/redis/) to store this kind of ruby data structure. suppose this: node1server1 = { "volume1" => 10400, "volume2" => 11221, "volume3" => 13212, "volume4" => 17227 } node1server2 = { "volume1" => 17450, "volume2" => 14241, "volume3" => 15512, "volume4" => 12427 } node2server1 = { "volu...

Ruby (off the Rails) Hosting

Many people have asked about Rails hosting on this site, but I'm not familiar enough with the back end of things to know if there's a difference. I want to host some Ruby CGI 'webservices', basically just ruby methods that take parameters from a POST request, access a MySQL db and return data. I've looked at RoR and it seems like overk...

RSpec: Expecting a message multiple times but with differing parameters

I currently have some expectations set up on a mock with consecutive calls: The spec: @my_mock = mock("a_mock") @options1 = {:some => "option"} @options2 = {:some_other => "option"} @first_param = mock("first_param") @my_mock.should_receive(:a_message).with(@first_param, @options1) @my_mock.should_receive(:a_message).with(@first_param...

Match string that ends with a given substring, except for certain cases, in Rails.

hi All, I have a regex /(.+)_id$/ in a rails application that matches any string that ends with _id . I need it to match any string that ends with _id except associated_id. How can I accomplish this? thx :) -C ...