ruby

Finding the next ActiveRecord model object in the database using given object

I have an ActiveRecord model object @gallery which represents a row in the Galleries MYSQL table. Is there a way for me to ask @gallery to give me the id to the next gallery object in the table? The obvious way for me to do this is to : @galleries = Gallery.find(:all) index = @galleries.index(@gallery) @nextgallery = @galleries[index+...

Accessing the version of a gem with ruby

How can I get the version of a gem using just ruby, I'd rather not use a system call and grep it the shells out put like so: `gem search passenger`.scan(/(?:\(|, *)([^,)]*)/).flatten.first => "2.2.9" Can't I just get it somehow with: Gem::Version I just don't know how to specify the gem i want... like in this case I want to get the...

Need a Standard Library Reference for Ruby

I need a good reference for how to use standard Libraries in Ruby. What confuses me about current libraries is that they don't describe or give examples like say Java's. Yet this is where examples are much more needed (in Ruby), because I am not familiar with how the called method will yield! So I am left with having to look at the sourc...

Ruby on Rails: RSpec and Acts As Audited (disabling acts_as_audited while testing?)

Hi everyone. I've been getting an error, which I think could be solved by disabling acts_as_audited when running tests, or at least stubbing current_user in audit sweeper. The error is below. What do you think I should do? NoMethodError in 'Order should create a new instance given valid attributes' You have a nil object when you didn't ...

Rails index of an association

I find myself requiring this. Assuming cart is a model which has a list of users. def index_of_item cart.users.each_with_index do |u, i| if u == current_user return i end end What's an easier way to get the index of an association like this? ...

How do you run tests in Sinatra ?

I have no idea how to test my Sinatra application. Do I just run ruby That does not seem to work. All files out there only talk about how to write the contents of the file, but not about how to get it running. Thanks ...

What are the major differences in object models of dynamic languages like Smalltalk, Ruby and Python

I dived into understanding the Ruby object model in the last weeks, and although so far was only a user of the fruits of ruby's and python's object in the past, I became curious how these things might differ in other languages. Years ago I touched smalltalk's squeak. Smalltalk is often figuring as a referential object oriented language,...

Pagination with MongoDB

Hey, I have been using MongoDB and RoR to store logging data. I am pulling out the data and looking to page the results. Has anyone done paging with MongoDB or know of any resources online that might help get me started? Cheers Eef ...

GObject Subclassing in Ruby for custom CellRenderer in GtkTreeView

I am trying to implement a customized CellRenderer in Ruby/GTK, and I've already found this suggestion: GObject subclassing in Ruby However, when I try the following: class CellRendererCustom < Gtk::CellRendererText type_register #register within gobject system? def initialize super end def get_size(widget, cell_area) ...

is there a ruby interface to ms project server?

is there a way to connect to ms project server using ruby? we are using MS project server 2007 ...

Mechanize on HTTPS site.

Have any of you guys/girls have used ruby's Mechanize library on a site that required SSL? The problem I'm experiencing at the minute is that when I try to access such a website the mechanize tries to use standard http protocol which results in endless redirections between http// and https:// ...

How to allow other view have the delete_class_path in RoR?

I have a object called "category", in my view/store/manage.html.erb, I want to do this : <%=link_to_remote category.name, :url => delete_category_path(category), :confirm => 'Are you sure?', :method => :delete%> But it show me the NoMethodError, how can I do that? This is the error from RoR: undefined method `delete_categ...

Profiling a ruby / ruby on rails application

Hi, I am looking to understand conceptually what all goes in profiling a ruby or ruby on rails program (e.g. memory usage, speed of request dispatching, speed of connecting with external programs like DB) and what are the best tools (at a conceptual and fundamental level) that are available Thanks ...

datamapper secondary key

Hello, I am using datamapper in a ruby application and I'm facing a problem I do not understand. I have a Appartment model and a Location model. An appartment is at a given location and several appartments can be at the same location. This typically described a 1-n relationship (I guess :-) ) My feeeling is that in the Appartement sql ...

Embed same comment page in RoR?

I have a div id called common, the content that I would like to appear in this div is in the file share/_common.html.erb What should I put in place of <!-- content from _common.html.erb --> so that the contents of share/_common.html.erb appears in the div? <div id="common"> <!-- content from _common.html.erb --> </div> ...

Problem to run Sphinx on Ruby on Rails 2.3.2

Hi, Yesterday I was trying to install Sphinx for full-text search on Windows 7. So, I followed their website's installation steps. Once I installed its windows service, I ran the indexer and then the test search against my app database and it worked great. Then, I wanted to make it work on Ruby on Rails 2.3.2, so I downloaded and insta...

Encryption Algorithm from PHP to Ruby (Vignere variant)

Hey all, I am a bit stuck with this. I have to interface with an api that uses a version of an encryption algorithm that they seem to have ripped from Typo3 written by Ari Kuorikoski. I need to create a ruby lib to interface with their api, so have to port their algorithm into ruby, and I am a bit out of my depth when it comes to encry...

Calculating MD5 of UTF-8 encoded string

Does anyone know how to reproduce this C# algorithm in Ruby? HashAlgorithm algorithm = MD5.Create(); Encoding encoding = new UTF8Encoding(); var sb = new StringBuilder(); foreach (var element in algorithm.ComputeHash(encoding.GetBytes(password))) { sb.Append(element.ToString("X2")); } return sb.ToString(); It calculates the MD5 ha...

How do you handle SNMP v3 Traps in Ruby?

I currently have a script that listens for incoming traffic for e-mail / syslog / and SNMP v1, I'm looking to add functionality for SNMP v3 but the ruby SNMP library doesn't include v3 support. I prefer it to be a ruby only solution because this tool will be used by others and I don't want to require them to install something like net-s...

what does !! do in ruby?

I am using some code that uses this syntax (restful authentication). def logged_in? !!current_user() end Tried googling for this but it just seems to ignore "!!", will accept an answer that can tell me how to find info about searching for strings such as !! in google. ...