ruby

Need help in Timezone in Rails ActiveRecord

Hi, I am faced with a peculiar issue with respect to Timezone in Ruby. I want to convert the following Sat Sep 11 15:15:00 +0530 2010 to Sat Sep 11 15:15:00 -0400 2010 As you can notice, only the time zone has been converted and no other part has changed. How to do this in Ruby. ...

Can you put a variable in a regexp?

I'm trying to validate wether a Model.category equals any existing Category name unless Category.exists?(:name => self.category.downcase) I had to put downcase in this to ensure all of them were downcased so they could match up as strings. But its a big server hit to update the attribute before_save, and I was thinking of just matchin...

RuntimeError: -ERR Unknown Command running redis gem on Ruby

The environment: Ubuntu 9.10 (run within VirtualBox) Ruby v1.8.7 Redis gem v2.0.6 On irb, when I try to initialize Redis I get a RuntimeError. Here's a snippet: irb(main):001:0> require 'rubygems' => true irb(main):002:0> require 'redis' WARNING: using the built-in Timeout class which is known to have issues when used for openi...

How do I test for belongs_to and has_many in Rails?

I'm using rspec and I'm trying to test whether or not my model y has many x. I've tried all sorts of things, including looping through the methods array, and can't seem to find a good method online. So what should I use? ...

User management using sinatra

Hi, I need to make a basic user management system for my application using Sinatra but I'm not sure how I should think about it. It needs to: Register User Login User How should I think about it? This shouldn't be hard, I'm just very new to all this. Thank you. ...

Should I use ruby 1.9.2 when starting a new Rails 3.0 project?

App will run on Heroku Dependencies include paperclip haml compass devise aws-s3 Reasons for or against? Any recommendation on another version of ruby? Update Heroku currently doesn't support 1.9.2 but it's expected to very soon based on this post. Rails 3.0 officially supports 1.9.2 (but not 1.9.1), so I decided to go ahead and ...

rails log issue

how do i fix this issue and get it to stop happening CONFLICT (delete/modify): log/development.log deleted in eccc398bb3058c5c0cc9e3587aae93289597fc0f and modified in HEAD. Version HEAD of log/development.log left in tree. I have it in .gitignore ...

Ruby Regex: Math on Backreferences

I need to replace all minutes with hours in a file. Assume a raw file like this: 120m 90m Should change to: 2h 1.5h ...

Boson vs Thor for console applications

Has anyone used both: Boson: http://tagaholic.me/2009/10/14/boson-command-your-ruby-universe.html and Thor: http://github.com/wycats/thor Thor are very popular and have more followers and contributers than Boson, but Boson looks far more powerful than Thor and the architecture is very well thought out. In Boson you: can add method...

In Ruby, why Time.parse() isn't defined but Time.now() is?

I think to use Time.parse(), it needs to have a require 'time' but why Time.now is usable but Time.parse is not? ...

In Ruby, how to parse "9/12/2010 7:02pm"?

It seems that Time.parse will treat 9/12/2010 as December 9, 2010: irb(main):012:0> RUBY_VERSION => "1.9.2" irb(main):013:0> Time.parse('9/12/2010') => 2010-12-09 00:00:00 -0800 irb(main):014:0> Time.parse('9/12/2010 7:10pm') => 2010-12-09 19:10:00 -0800 I can use Regex to mess with the order and parse accordingly, but is there a di...

Rails App using Selenium but NOT for Testing -- How to organize ?

I am creating a rails app that is meant to be run locally and automate some of my web based tasks. The reason for rails is that I will import data in, select a number of tasks to be completed, then tell it to start. Ideally i will keep logs of runs and keep track of what tasks were completed during specific runs. My experience with...

Pros/Cons of storing serialized hash vs. key/value database object in ActiveRecord?

If I have several objects that each have basically a Profile, what I'm using to store random attributes, what are the pros and cons of: Storing a serialized hash in a column for a record, vs. Storing a bunch of key/value objects that belong_to the main object. Code Say you have STI records like these: class Building < ActiveRecord:...

Ruby/Rails constant behavior

I am new to Ruby (coming from java background) and I was wondering whats the behavior for constants in RoR applications and in general Ruby. Are they just initialized once, like java static variables? I am initializing a fairly big array of hash as a constant, so I want to be sure if I am doing it right? Thanks for your help. module...

how to generate .htaccess password locally (by ruby)?

Is there a ruby script to generate password for .htpasswd? Thanks! ...

Ruby: Breaking Up CSS Into Blocks with Regex

I have a stylesheet: a,b,c { stuff lots of it } b { more stuff } .test { even more } I want a regular expression to break it up into each of the three parts, separating from '}' to '}' should work alright for my needs (except the first case obviously). ...

Rubygems Chronic cannot parse "2010-09-12 3:12pm" but can parse "2010-09-12 3pm" or "last monday 3:12pm"?

It seems strange that "2010--9-12 3:12pm" is a weak spot of Chronic Rubygem? Is there a way to make it work? (or another gem that can do it?) I also hope to find a parser that can handle 2010-09-12 3:12pm UTC or other timezones such as PDT, PST, or UTC+8 or -0700 irb(main):001:0> RUBY_VERSION => "1.8.7" irb(main):002:0> require 'rub...

gem --version different to sudo gem --version :(

I'm a bit of a Linux noob trying to get ruby, rails, mysql and sqlite all playing nicely on ubuntu 10. I am getting errors, and I realized that the versions are different for sudo versus normal user! mpw@ubuntu:~/.rvm/gems/ruby-1.9.2-p0$ gem --version 1.3.7 mpw@ubuntu:~/.rvm/gems/ruby-1.9.2-p0$ sudo gem --version 1.3.5 I have used RVM...

Ruby $stdin.gets without showing chars on screen

I want to ask users to type in a password, but i dont want the chars to appear on screen as they type. How do I do this in Ruby? Thanks ...

Library for kademila end emule

Anyone known a ruby (or at least python or java) library for kademila and emule? ...