ruby

wrong number of arguments (1 for 0) has_many_association.rb:61

I am upgrading my app from Rails 2.2 to 2.3.5 and I am seeing the following error while using '<<' for saving a has_many relationship. Eg: Breaks test ev = UserEvent.new # model specific code here self.user_events << ev Eg: Works ev = UserEvent.new # model specific code here ev.user_id = self.id ev.save! This worked fine with Rail...

Rails migration error: undefined method `install_helpers' for ActionController::Routing::Routes:Class

Got a couple of Rails 2.3.5 projects that are giving me this error when I try to run a rake db:migrate. Wondering if someone else has seen it: undefined method `install_helpers' for ActionController::Routing::Routes:Class Migrations used to run fine. I've got a pretty tame routes.rb but a lot of gems and plugins, one of which may be th...

Convert a String Containing an Array to an Array in Ruby

I have a string that contains an array that i would like to convert into an array. How would you do this? I want to convert this: myvar= "[[Date.UTC(2010, 0, 23),0],[Date.UTC(2010, 0, 24),0],[Date.UTC(2010, 0, 25),3],[Date.UTC(2010, 0, 26),0],[Date.UTC(2010, 0, 27),0],[Date.UTC(2010, 0, 28),0],[Date.UTC(2010, 0, 29),0],[Date.UTC(2010,...

How to require a block in Ruby?

Is there any built in way to require that a block be passed to a Ruby method? I realize I can just raise an exception if block_given? is false, but is there some nicer way to do it? ...

How do I get constants defined by Ruby's Module class via reflection?

I was trying to get Matz-n-Flanagan's RPL book's metaprogramming chapter into my head. However I couldn't understand the output from the following code snippet that I dreamed up. p Module.constants.length # => 88 $snapshot1 = Module.constants class A NAME=:abc $snapshot2 = Module.constants p $snapshot2.length ...

How to highlighting differences between 2 html files

My web application has job descriptions. These job descriptions can be modified by some users. Each modification result in a new version of the job description. The content of the job description is edited by the users, in html, directly in the textearea using the tinymce editor. I want to be able to show a user the modifications made ...

how to define a class without 'class' statement in Ruby ?

I have many classes to define, but I don't want to repeat the below work: class A < ActiveRecord::Base end Is there any declaration statement to define a class without using the class statement? ...

How to avoid updating update_at flag while updating associated model in active record?

My association to models as follows People model belongs_to :category has_one :account, :through => :category category model belongs_to :account has_many :bookings account model has_many :categories Level model accepts_nested_attributes :peoples I wrote @level.update_attributes(params[:level]) in Le...

What is the correct way of ensuring a single instance of a class?

In java I would create something like this: private static MyClass instance; public static MyClass getInstance() { if(instance != null) { return instance; } instance = new MyClass(); return instance; } What is the appropriate way to obtain the same functionality in ruby? Update: I've read about 'include Singleton' but wh...

how to convert 270921sec into days + hours + minutes + sec ? (ruby)

I have a number of seconds. Let's say 270921. How can I display that number saying it is xx days, yy hours, zz minutes, ww seconds? ...

Is the keyword "STDOUT" ruby- or cygwin-specific in this command?

Hi guys, The following command which you can use in the cygwin console to output text in this console. ruby -e 'STDOUT << "ABC" << " DEF"' My question is: the STDOUT part is a ruby keyword or a cygwin keyword? How can I use it? Great thanks. ...

% string formatting doesn't work in class methods? (ruby)

any idea how I can display headers using % for formatting? I does nothing in class method but works nicely in instance method class Stats attr_accessor :type, :count; def initialize type @type = type @count = 0 end def self.display "%s %4s " % ["header1",'header2'] #puts 'headers' ObjectSpace.each_object(Stats) { |...

Using activeResource without Rails

Hi i'm developing a rails application that expose some methods via activeResource. I want to access these resources through a simple remote ruby script. I want to know if it's possible use activeResource without Rails ...

Is it possible to evaluate a Ruby DSL in a non-global context?

I'm using Blockenspiel to create a DSL with Ruby. It works great and solves a lot of my problems, but I encountered the following problem that is not strictly related to Blockenspiel. Suppose I have a DSL that looks like this: dish do name = 'Pizza' ingredients = ... nutrition_facts = ... end dish do name = 'Doner' ingredie...

Parsing a log file with Ruby using range operator

I have a log file that consists of many timestamps in this fashion: [2010/02/21 11:01:25] since the log files are large, I'd like to use a quick Ruby excerpt to be able to see just the text between two inclusive times.. say from 11:01..11:59 Using something like while line = gets puts line if line =~/start/ .. line =~ /end/ end ...

What's the correct syntax for options when generating Blueprint CSS files in SSH with Ruby command?

I need to generate default Blueprint CSS files using a Ruby command in the Shell. However the column_width, amount and gutter parameters aren't coming trough. I think i don't understand the syntax... is this correct: ruby compress.rb -o /var/www/css/blueprint/src/ -p 70 15 12 for this documentation? joshua-claytons-computer:lib joshu...

LDAP - Authlogic

I have a ROR application with authlogic and LDAP, i follow the how to oh authologic and this http://pastie.org/385199 but the method (def valid_ldap_credentials?(password_plaintext)) is not called....any help ? ...

How do I log in to a site remotely using a script?

Hi all, I'm trying to write a script to automate a repetitive task I currently do manually. I would like to log in to a site remotely and inspect the returned page. I've been doing this by sending a direct POST request (the site is PHP, I'm pretty sure it's Joomla) with my login details and data for the other fields of the form from t...

What makes Rake so useful in Ruby?

Perhaps this is a dumb question, and I'm not under estimating the value of Rake here by any means, I'm just not getting it. What value does Rake have if all it is, is arbitrarily executed Ruby code? It's apparently good at handling tasks, but what's to stop me from writing a class and embedding it into a shared Ruby directory and executi...

regular expression

Hi i have a string like this: adfsdf dsf {{sadfsdfadf {{Infobox}} musical}} jljlk }} i want eliminate all substring {{..}} and so i tried with \{\{.*\}\} this eliminates {{sadfsdfadf{{Infobox}} musical}} jljlk }} but i want eliminate {{sadfsdfadf {{Infobox}} musical}} checking the }} more near from the start of the substring How ...