ruby

user profiles lookup-table values as constants (denormalised) or models (normalised)

My site contains user profiles with fields such as hair and eye color. I have been implementing lookup-table type fields with constants in my user model, ie. HAIR = %w[shaved black blond brown red grey white bald] EYES = %w[black brown blue hazel green grey other] used in my views with collection_select statements to populate drop...

what is ruby-on-rails' order of operations when constructing from a hash?

I have an Attendance model that allows the user to enter a starting, ending and break time, each as a ruby Time object. Each attendance also has a day (ruby Date object). I want the 'Date' elements of the times to be the same, so I override the assignment operators like this: def startTime= (t) self[:startTime] = Time.mktime(day.yea...

Ruby Inputs - Weird?

I'm a bit confused with the input's of Ruby. Whenever I try to get input, it doesn't register the 'Backspace' key. Also, it never accepts the 'Enter' first time. I always have to push 'Enter' after my input usually 3 times before it actually inputs it. For example, view source print? 1 my_var = gets.chomp If I wanted to enter 'Hell...

Address Parser for Ruby

Hi, Is anyone aware of an address parser plugin for Ruby? I might have to use one of the paid webservices but thought there might be a plugin. Another thought is go down the NLP route where I could build up a database over time. Does anybody use any NLP plugin for ruby? I want to use it to logically parse and sanitise something like...

How to modify Hash to enable access of element 'hash[:a][:b]' by shorter 'hash[:a,:b]' in Ruby?

I would be happy to access any element of multi-dimensional hash-array by a shorter expression h = {a: {b: 'c'}} # default way p h[:a][:b] # => "c" # a nicer way p h[:a,:b] # => "c" # nice assignment h[:a,:b] = 1 p h # => {:a=>{:b=>1}} I realize that in this way one eliminates the possibility to have a hash key being an array. {[...

What does the "Enclosing class/module 'mXPath' for class Object not known" message mean?

I updated a Ruby gem, and I got that message. Does that mean something has not been installed, and the gem is missing something? ...

How to use pict to generate test cases

I'm using pict (Pairwise Independent Combinatorial Testing tool) as my tool. I'm trying to generate test cases using these constraints: video_resolution: 352x240,352x288,640x480,704x480,704x576,720x240,720x480,720x576 video_rotate: 0,90,180,270 IF [video_resolution] IN { "640x480"} THEN [video_rotate]="90" OR "180"; but I'm having tr...

is it OK to use begin/end in Ruby the way I would use #region in C#?

I've recently moved from C# to Ruby, and I find myself missing the ability to make collapsible, labelled regions of code. It just occurred to me that it ought to be OK to do this sort of thing: class Example begin # a group of methods def method1 .. end def method2 .. end end def method3 .. e...

cascading drop down box implementation without ajax in ruby on rails

I am newbie in RoR and creating my first project. I have two models category and article.category has many article and article belongs to one category.I want to create cascading drop down boxes to display article.In first drop down box I want to select category which update second drop down box with articles which belong to the category....

Ruby: What does Errno::EEXIST mean when installing a gem?

I am trying to install a ruby gem called activeldap, however, it won't let me install it. I keep getting all kinds of errors including the Errno::EEXIST error. I added the error info below. Any ideas? C:\Ruby\www\demo>gem install activeldap ERROR: While executing gem ... (Errno::EEXIST) File exists - C: C:\Ruby\www\demo>gem install...

Why does this Nokogiri command strip out HTML tags?

Hi all, This is a continuation of a previous question. I'm having problems with this Nokogiri snippet: >> require 'nokogiri' >> html = 'bad<p>markup</p>with<img src="foo.jpg">' >> Nokogiri::HTML(html).at_css('body').children.map {|x| '<p>' + x.text + '</p>'}.join('') => "<p>bad</p><p>markup</p><p>with</p><p></p>" What happened to my...

Regex pop quiz of the day :D

If I have a string like so .. There is a lot of white space. And I want to remove all the unwanted space in Ruby's regex.. How do you identify white space and remove it so that there will still be at least one white space between all the words? So far I have : gsub(/\s{2,}/, '') B...

Ruby Load multiple xml from a directory in a program to parse them

Hi I want to load a set of xml from a directory and use REXML to parse all the xml in a loop. I cant seem to create File Object after i start reading from a directory i=1 filearray=Array.new documentarray=Array.new directory = 'xml' Dir.foreach(directory).each { |file| next if file == '.' ...

Ideas to extend this little project? - A pidgin web ui

I have built a little Web UI for Pidgin(respectively all libpurple based messengers) together with DBus and Sinatra. It was for fun and learning purposes and now I'm looking for ideas to extend it. Can you think of any useful applications or extensions for it? Since I work on this project to learn something new, ideas for other techno...

Custom to_json method not being called in Rails app

I have a Ruby on Rails application that I'm working on an API for an associated iPhone application. I have overwritten the to_json method of my Item model to return some custom information from the API request that I'll need in the iPhone app. However, when I use the built-in rails to_json method and include my Item model as an associa...

Change Ruby Environment in Hudson

I'm trying to point the Hudson app at the test environment in my MySQL database with Rails. Do I need to change the environment variable RUBY_ENV? If so, where do I implement this? ...

Exclusions in map in Ruby.

How do I create an exclusion for a array map in Ruby. Here's what I want to achieve, a = [1,2,3,4] b = [5,6,7,8] a.map.each do |x| b.map.each do |y| if !(x == 1 && y == 7) puts "#{x} and #{y}" elsif !(x == 4 && y == 8) puts "#{x} and #{y}" end end end 1 and 5 1 and 6 1 and 7 # still here 1 and 8 2 and 5 2 an...

radrails dev server startup error: load_missing_constant

Here is the stacktrace I get in the console: C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:443:in `load_missing_constant': uninitialized constant ActiveRecord (NameError) from C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:80:in `const_missing' from ...

Cucumber table.diff saying tables are not identical - Rails

Hi. I am very new to Rails and Cucumber so this may or may not be a quick fix. I have a cucumber scenario that loads a collection of models and then checks to see if they are all rendered to a table. Cucumber returns a result saying "Tables were not identical". What am I missing here? I have tried to add headers in the second step defin...

Telling rspec to not load files

I'm trying to add some commit hooks to my git repo. I want to leverage Rspec and create commit message specs that will run each time I commit. I have figured out how to run rspec outside of the 'spec' command, but I now have an interesting problem. Here is my current code: .git/hooks/commit-msg #!/usr/bin/env ruby require 'rubygems' ...