ruby

How to get TimeWithZone within rails3 unit/test

Hi, I'm trying to test a rails, application, and in one particular case, I need to create a TimeWithZone object inside my testcase. So I write sth like this: started_at = ActiveSupport::TimeWithZone(started_at, Time.zone) only to get an error: NoMethodError: undefined method `TimeWithZone' for ActiveSupport:Module I tried requiri...

Howto Uninstall RVM

How can I uninstall (or reinstall) RVM on Ubuntu 9.10? I messed up my current installation. ...

starting and stopping a daemon at user login logout

I have a daemon script written in ruby which responds to commands like daemon start and daemon stop. It's executable with shebang #!/usr/bin/env ruby and it works invoked from terminal. I need to start the daemon on login and stop it on logout. Background info: KDE, zsh. I already tried to make two separate shell scripts with daemon st...

Rails tests can't find test_helper

Hi folks, I'm trying to run individual tests through ruby test/unit/mytest.rb, but I always get a "no such file to load - test_helper" error. Google brought up a few suggestions, but none of them worked for me. I'm running Rails 3.0, Ruby 1.9.2 (through RVM) on Ubuntu 10.10 Here's what I've tried so far - any suggestions really appreci...

Which programming language/framework shall I choose for this project?

Hi, I have two projects ahead and I'm pretty new at Ruby and Ruby on Rails. It's real fun! =) Besides, I count myself fluent in C++ and Java (and JavaEE), but have very very few experience with C#.NET and Ruby. Also, I'm pretty eager to learn Ruby, but don't really want to waste time to develop skills on C# - which is pretty similar to ...

Simple regular express question

I have a title on a blog goes like this Main Idea, key term, key term, keyterm I want the main idea and the key terms to have a different font sizes. First thing that came to mind was to search for the first comma and the end of the string and replace that chunk with the same thing but surrounded by span tags with a class to make the fo...

Order/randomize/convert array in rails

Hi, I've got this: a = [[123,1],[124,1],[125,1],[126,2],[127,3],[128,3]] And I would like to turn a into b: ordered by value random within array of value // updated: b = [[124,123,125],[126],[128,127]] How to do this in ruby? Im using rails. ...

Passenger stalls with a large amount of simultaneous requests

I'm having trouble with one of our Rails 3 app's. When a lot of requests are sent to the server (10 / second) the whole server stalls. I tried a lot of different passenger setups and sometimes I noticed a slight improvement but none of them ended up to be a solution. My setup: Intel i7 (8 cores) 8GB ram Ubuntu 10.04 Server Ruby 1.9.2 ...

Generating a QR code in rails

Hi Guys. I want to generate QR codes in ruby on rails, to run in the background of my website written in rails. Saw this http://code.google.com/p/qrcode-rails/ but cannot work out how I could get this to work for me. Basically in RoR I want to: Pass a generator a string, my unique code, a 20 character length number (e.g. 320329288899988...

IronRuby doesn't recognize 'rake' - I'm getting undefined method `rake' for main:Object, how to fix?

Hi All, Just installed IronRuby 1.1. I'm trying to take a look at rake and albacore. After installing ironruby, I am able to hit a command prompt by typing ir, and I am able to do simple puts, but when I try to run rake, I get the error undefined method `rake' for main:Object How do I resolve this? Any ideas? Thanks, ~ck in San D...

Why is rake db:migrate:reset not listed in rake -T?

Why are some rake tasks not listed by rake -T? Like db:migrate:reset? I can execute it without a problem, but why is it not listed there? Is there a way to get a real full list of rake tasks? % rake -T (in /home/zeus/projects/my_project) rake about # List versions of all Rails frameworks and the environment rake db:create ...

Why does Rails use helper methods like link_to instead of <a href...>?

I am learning Rails and I have noticed that Rails continously uses helper method such as link_to instead of just using plain html. Now I can understand why they would use they would use some helper methods, but I don't understand why they would prefer helper methods over just coding the html directly. Why does Rails prefer helper method ...

Ruby: Hash Assignment/Parse from Text

Looking to create a hash table from a text output that looks like this (whitespace between words are tabs): GCOLLECTOR 123456 77889 uno BLOCK unique111 error fullunique111 ... ... ... DAY ... ... ... LABEL detail unique111 Issue Broken - The truck broke LABEL detail ...

Setting cell/column widths on a Prawn table

Hello! I'm making a little script with ruby which produces a week schedule PDF file, using Prawn as a PDF library and I'm struggling with styling the table. I'd like to set a static width for all the columns in the table so that the widths wouldn't depend on the contents of the cells. I've read the documentation (lots of room for improv...

Keep getting "coerce must return [x, y]" error with rturk gem

I swear this was working a few weeks ago but I keep getting "coerce must return [x, y]" when I use the rturk gem to create a hit. RTurk.setup(configatron.amazon.access_key_id, configatron.amazon.secret_access_key, :sandbox => true) hit = RTurk::Hit.create(:title => "SOMETESTTHING" ) do |hit| hit.assignments = 5 hit.description = "FOO...

TokyoCabinet ruby binding install problem

I get the same issue attempting to install tokyocabinet's ruby bindings from source or from a gem: tokyocabinet.c: In function 'fdb_get_reverse': tokyocabinet.c:2377: error: 'TCFDB' undeclared (first use in this function) tokyocabinet.c:2377: error: 'fdb' undeclared (first use in this function) tokyocabinet.c:2383: error: expected expre...

Fixed Object Id for System Objects and Small Integers in Ruby

Why do system objects like nil, true or false have a fixed object id in Ruby. Also I tried printing out the object ids of numbers, they are the same and follow an odd number sequence pattern. Any explanation for this? [nil,true,false].each { |o| print o.object_id, ' '} 4 2 0 => [nil, true, false] >> (0..50).each { |i| print i.object_id...

Ruby on Rails Incorrect Primary Key Names

Hi I'm using RadRails to create my MYSQL databsase tables. This is migration task: class CreateEvents < ActiveRecord::Migration def self.up create_table :events do |t| t.string :eventname t.string :evententryurl t.string :eventurl t.timestamps end end def self.down drop_table :events end e...

Print to server screen in socket

Is there any reason why the server process does not give any output in the following code? require 'socket' server = TCPServer.open(3000) loop{ puts "waiting for connection" client = server.accept puts "connection!" client.close puts "client closed" } I connect via: nc localhost 3000 in a windows cygwin environ...

What is the best way to store procedures/code?

Hello, I have a feed reader written in Rails (the logic is bit complex as I am scraping some data) and I am trying to generalize the methods. Here is my current structure - Class Gizmodo def update update logic end end Class Wired def update update logic end end Now I am thinking of structure like this Cl...