ruby

Reusing Code from Another Rails App

I am trying to reuse some code from another rails application I had worked on earlier. I copied over all the models / views / controller / migrations and ran rake db:create and migrate. Now when I try to run the application the initial page for this view (the one that has the list edit/delete) loads fine and shows there are 0 records. Wh...

How do I enable text selection, copying, and pasting in a Shoes app?

Hi Shoesers, Is there any way to allow text selection, copying and pasting in a Shoes app? I'm making a little utility, and it would be great if it could support this functionality. I know shoes uses Pango/Cairo for text rendering, so I imagine there's a way to turn this on. Anyone? _why? Also, _why, thanks for the great toolkit! ...

Fixtures and Selenium and Rails (oh my?)

What data do you use with Selenium tests on Rails apps? Do you load from fixtures? Use an existing dev db? Use a separate (non-fixture) db? I'm considering my options here. I have a Rails app with a large Selenium test suite that runs on a modified version of Selenium Grid. Part of the process, right now, is loading a large set of fixt...

How do you make a case for Django [or Ruby on Rails] to non-technical clients.

Businessmen typically want a web application developed. They are aware of .net or J2EE by names, without much knowledge about either. Altho' Rails and Django offer for a much better and faster development stack, it is a big task to convince businessmen to use these platforms. The task begins with introducing Django (or Rails), quoting ...

Find the associations for an ActiveRecord class at run-time?

I would like to find the assocations of an ActiveRecord class at runtime... Let's assume I have the following: class Person < ActiveRecord::Base has_many :chairs has_many :pens end class Chair < ActiveRecord::Base belongs_to :person end class Pen < ActiveRecord::Base belongs_to :person end How can I find out at runtime that...

How do you deploy a Ruby on Rails application on hostgator?

How do you deploy a Ruby on Rails application on hostgator? ...

String interpolation when not using a string literal

I have a Ruby script that used string interpolation to build error messages. p "#{vName} is not a defined variable" => 'xxx is not a defined variable' Another programmer came through and attempted to externalize the string literals to a separate configuration file. Of course, he doesn't get the substitution. p err_string_from_config...

How do Ruby symbols work?

I read that Ruby has a language featured called "labels", how does that work? Update: I saw it at http://ruby.about.com/od/gems/qt/shorturl.htm where the author talks about a label at the bottom of the article with: puts ShortURL.shorten('http://ruby.about.com', :lns) ...

Ruby on Rails Single Table Inheritance (STI) and unit test problem (with PostgreSQL)

I'm using an STI model with a single "Accounts" table to hold information for Users and Technicians (i.e. User < Account, Technician < Account). Everything works from a functional perspective, but things explode when running unit tests: ... 8) Error: test_the_truth(UserTest): ActiveRecord::StatementInvalid: PGError: ERROR: relation "t...

Saving updates to objects in rails

I'm trying to update one of my objects in my rails app and the changes just don't stick. There are no errors, and stepping through with the debugger just reveals that it thinks everything is updating. Anyway, here is the code in question... qm = QuestionMembership.find(:first, :conditions => ["question_id = ? AND form_id = ?", q_id,...

Why does new Rails db migration file start with datestamp instead of sequence number?

Whenever I use script/generate to generate a new scaffold for a change to my Rails database, the new migration file is prepended by a datestamp (e.g. 200903140912_create_users.rb) instead of a sequence number (e.g. 004_create_users.rb). I then have to manually change the file name to fit in with the rest of the migration files. Does an...

Converting an empty string into nil in Ruby

I have a string called word and a function called infinitive such that word.infinitive would return another string on some occasions and an empty string otherwise I am trying to find an elegant ruby one line expression for the code-snippet below if word.infinitive == "" return word else return word.infinitive Had infinitive re...

RSpec Gem does not seem to install dependencies...

$> jruby -v jruby 1.1.4 (ruby 1.8.6 patchlevel 114) (2008-08-28 rev 7570) [x86-java] $> gem install rspec JRuby limited openss loaded. gem install jruby-openssl for full support. http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL Succesfully installed rspec-1.1.12 1 gem installed Installing ri documentation for rspec-1.1.12... Installin...

How can I add TimeoutHandler to EvenmentMachine connection.

Hi, list Now I am coding for one non-blocking httpclient based on event-machine, and it seems the client will hang for 50 seconds if the destination is unreachable. My questions are How can I short the timeout? I had tried conn.set_comm_inactivity_timeout(5), but it didn't work How can I add TimeoutHandler to the connection? Thanks!...

Ruby/Rails thread safety

I have been hacking with Ruby from time to time, but I haven't done anything big or multithreaded with it. I have heard that MRI only supports green threads and JRuby supports native threads via JVM. However, I stumble upon comments on blogs and discussion groups which say that "Rails is not thread-safe" or that Ruby itself is not thread...

Backslashes in Single quoted strings vs. Double quoted strings in Ruby?

I'm a little confused about when to use single quoted strings versus double quoted strings. I've noticed that if I put a variable inside a single quoted string, it doesn't get interpreted. Also, if I use a newline character in a double quoted string, it causes the string to be displayed over two lines whereas in a single quoted string th...

Nokogiri: Searching for <div> using XPath.

I use Nokogiri (Rubygem) css search to look for certain <div> inside my html. It looks like Nokogiri's css search doesn't like regex. I would like to switch to Nokogiri's xpath search as this seems to support regex in search strings. How do I implement the (pseudo) css search mentioned below in an xpath search? require 'rubygems' requi...

Rails with Non-Rails Database Design

Complete newbie researching Rails. Can Rails be used with a read-only schema that doesn't conform to the Rails' default naming and design conventions? For example, my database's schema has base tables that use string columns for unique primary keys. For example, a base table called Jobs, might have a unique primary key defined as Jo...

combine regex in ruby

Given this text: /* F004 (0309)00 */ /* field 1 */ /* field 2 */ /* F004 (0409)00 */ /* field 1 */ /* field 2 */ how do I parse it into this array: [ ["F004"],["0309"],["/* field 1 */\n/* field 2 */"], ["F004"],["0409"],["/* field 1 */\n/* field 2 */"] ] I got code working to parse the fir...

Equivalent to exclamation mark for method names from ruby in other languages

In Ruby, methods with side effects or methods that change the object passed as parameters have "!" as a postfix. For example: "SomeString".gsub!(/S/, "s") would be changing the String object, while "SomeString".gsub(/S/, "s") would work on a copy of the String object, and would not change the state of any objects outside of the method...