ruby

Porting Rails 2 application to new server

I've posted a couple other questions during this process, but I have a better idea of what I'm trying to do so I thought I'd ask about that. I've inherited a Rails 2.2.2 application, which is currently running in production form on a server I have access to. I'm trying to port that application over to my server, version control, etc. I ...

What's the best way to define a scope inside of a module in Rails 3?

I have a number of models that need the same scope. They each have an expiration_date date field that I want to write a scope against. To keep things DRY, I'd like to put the scope in a module (in /lib) that I'll extend each model with. However, when I call scope within the module, the method is undefined. To work around this, I use c...

Can node.js replace Ruby?

Hi, I'd like to know if it's possible to create a complete website using node.js (just like we do using Sinatra and Rails). Also, is there any framework as good as Sinatra and Rails? Is this the best use for node? Regards. ...

In Ruby, some good ways to convert everything in array of hash values from float to int?

I have an array of hashes, and the values are all float numbers. What are some good ways in Ruby to convert them all to int? I have this way right now but wonder what other methods there are that are more elegant or clear: analytics.map {|e| e.keys.each {|k| e[k] = e[k].to_i}; e} Update: this is a run of the code: > @analytics = [...

When to use node.js vs sinatra vs rails?

Hi, What are the best uses for these 3 languages/frameworks? Is it useful to mix all of them (or 2)? ...

find_by_sql equivalent for mongoid?

Is there some sort of find_by_sql equivalent for mongoid, where you pass a mongo query and it materializes Mongoid::Document s from the results? ...

ruby's oauth2 grant_type

Hi, i started using oauth2 gem by intridea (http://github.com/intridea/oauth2) and don't know how to fix this problem. I have developed both client and server and on request for access_token i see no grant_type parameter. My code from client callback controller class CallbackController < Devise::OauthCallbacksController def accounts ...

Ruby YAML::load

I'm trying to modify the default deserialization of the built-in timestamp format, to affect Ruby's Time. I do this (successfully) with Hash: YAML::add_domain_type('yaml.org,2002', 'map') { |t, v| nil } YAML::add_domain_type('ruby.yaml.org,2002', 'hash') { |t, v| nil } hash = { :hello => :world } puts YAML::load(hash.to_yaml) # nil B...

Authentication for Rails 2.3.8 using MongoDB and mongo_mapper

Hi All, How will I do authentication using Rails 2.3.8 using MongoDB and mongo_mapper? Let me know your expert advise on this. By the way, a Rails noob here :) Thanks! ...

Ruby, get hours, seconds and time from Date.day_fraction_to_time

I've found this method here. start = DateTime.now sleep 15 stop = DateTime.now #minutes puts ((stop-start) * 24 * 60).to_i hours,minutes,seconds,frac = Date.day_fraction_to_time(stop-start) I have the following error: `<main>': private method `day_fraction_to_time' called for Date:Class (NoMethodError) I've checked /us...

arel, how to join

Given class Category < ActiveRecord::Base has_many :products, :order => 'name ASC' end Using the Rails 3 stack, how can I query for all categories that 'have' products? ...

In Ruby, why is Hash[:a, 1] and Hash[[[:a, 1]]] giving the same result {:a => 1}, while Hash[[:a,1]] gives an empty hash?

> Hash[:a,2,:b,4] => {:a=>2, :b=>4} > Hash[:a,1] => {:a=>1} > Hash[[:a,1]] => {} > Hash[[[:a,1]]] => {:a=>1} ...

undefined method `to_json' for #<Hash:0x3d3cef0> (NoMethodError) in ActiveSupport 3

Did to_json get removed or something? ...

Rails Associations (belongs_to, has_many) can't save 2 ids in table with a create method (user, post, comment)

Hi, Trying to write a basic "blog-like" app in rails 3, I'm stuck with associations. I need the create method save the post_id as well as the user_id in the comment table (which I need in order to retrive all comments written by a user in order to display it) The app has users (authentication - devise), posts (posted by users - but I'm...

Problem with treetop grammar, not matching all options

I am writing a small, really simple lisp parser in ruby with the treetop gem just to experiment with it. However, it is not really working out how I want it to, and the documentation is pretty poor so it's hard to understand what I am doing wrong. Currently, the grammar can match both a symbol and a boolean, but not a number. However, wh...

Is there a way to run a rake task without running the prerequisites?

Is there a command line switch I'm missing? At the moment I'm having to do this: #task :install => :build do task :install do end ...

selenium RC ruby, wait for hidden element to appear?

Hi I was just wondering how i can wait for a hidden element to appear on the page, i triedni seleum.is_element_present but it dosent seem to be working. thanks ...

How do I detect plaintext in a MIME file?

I have a large set of MIME files, which contain multiple parts. Many of the files contain parts labelled with the following headers: Content-Type: application/octet stream Content-Transfer-Encoding: Binary However, sometimes the contents of these parts are some form of binary code, and sometimes they are plaintext. Is there a clev...

Having trouble with Ruby hashes

I'm using Watir and Ruby to try and slurp a load of data from a web application into a hash: def getOrders( ) return orders = slurpOrders() end def containsOrderNumber( orderNumber ) puts orderNumber orders = getOrders puts orders[orderNumber] #puts orders.keys puts "orders has_key? = " + orders.has_key?(ord...

Rails 3 with mysql problem

Hello, I have updated to rails 3 on my Snow leopard. Previously i use sqlite for development. It's working fine when i rake db:create. Now I'm trying to install mysql on my mac. I downloaded mysql-5.1.50-osx10.6-x86.dmg Installed all three file.(mysql-{version}-osx10.5-x86.pkg, MySQL.prefPane, MySQLStartupItem.pkg) execute this to in...