ruby

Alternatives to abstract classes in Ruby?

I am new to Ruby. A simple example, what I need: class Animal abstract eat() class Cat < Animal eat(): implementation class Dog < Animal eat(): implementation In other words, the eat() method should be required for all the classes which extend Animal. In JAVA I would just use an abstract class, but after doing so...

How find out gem install options?

Hi I'm trying to install all my gems in ~/.gems. I wanted to install ferret as user but it doesn't work, because ferret need to install in /usr/bin. My question is, how to I find out which options (like install to different bin folder) exists, when I install gems? ...

Sourcing rvm from my Ubuntu .profile only works manually, not at login

I'm having trouble getting the Ruby Version Manager rvm to source from my Ubuntu 10.04 .profile. The code: [[ -s "$HOME/.rvm/scripts/rvm" ] && . "$HOME/.rvm/scripts/rvm" ...never does what I expect it to (i.e. give me the rvm program when I open a new shell or start a new session); but if I execute source .profile in a new shell af...

How to make this beautiful and short

filename = filename.gsub("_"," ").nil? ? filename.gsub("_"," ") : filename ...

Rails active record type for types that are within a group.

This is more of a design question. I have several places in models were I have records that have only a certain amount of option for them, for example: Sex: There is only 2 options (male, female) Level: There is only 3 options (silver, gold, platinum) Country: There is only a limited amount of countries. My question is what is the righ...

How to load configuration at startup in rails?

I have some configuration values in a YAML file that needs loaded when my app starts up. The values need to be accessed in a few different places (both in a few models and a few controllers). What is the best way to load, store, and access these? ...

Ruby Strange Error

Whenever I require a file in ruby or irb I get this error: LoadError: no such file to load -- (insert any filename).rb from <internal:lib/rubygems/custom_require>:29:in `require' from <internal:lib/rubygems/custom_require>:29:in `require' from (irb):1 from /usr/bin/irb1.9.1:12:in `<main>' It happens even if the file ex...

How do Rails associations look behind the scenes?

Can anyone point to some resource which shows how the tables are set up ( for MySQL for example ), on each of the Rails associations ( one to one, one-to-many, many to many ). I understand how the associations work from a Rails point of view, but I don't understand how they work from the database's side. ...

will paginate, nested routes, ruby, rails

I'm trying to get will paginate to link to my nested route instead of the regular posts variable. I know I'm supposed to pass some params to paginate but I don't know how to pass them. Basically there is an array stored in @posts and the other param paginate has access to is category_id. The nested route is /category/1/posts but hittin...

Can I change the expected Rails version of a Rails application?

I downloaded an archive containing code for a Rails application ( from a book I'm reading ). I'm running Rails 3.0.1 but the application fails to start, because it's looking for 3.0.0beta3. Is there some way of starting it with my version of Rails? ...

Category child of another category in rails

How to implement in rails a category that can be child of another category (self-referential has_one) ? Thanks ...

problem in bundler

I already gem bundler in system. I check "gem list". it show: *** LOCAL GEMS *** bundler (1.0.3) but I go to app and execute "bundle install". it is show: bundle: command not found please help me. ...

Rails Partial (Rails 3, HAML) arbitrarily slow

I'm using Rails 3.0.1, HAML 0.3.22, and Mongrel 1.1.5 (and MongoMapper not AR). I'm rendering a list, and each list item is it's own partial. Every time the page renders one of the list item partials takes almost 100X longer to render (and it is an arbitrarily different one each time. Also, needless to say, each item has essentially the ...

Rails distance_of_time_in_words returns "en, about_x_hours"

I'm having a weird problem, hoping someone knows what the issue is... Using distance_of_time_in_words (and consequently time_ago_in_words) is not returning the actual time distance. Instead it is returning things like "en, about_x_hours" or "en, x_minutes". The pattern is correct, as in: time_ago_in_words(50.minutes.ago) => "en, about...

RVM and global gems

I'm running Mac OSX 10.6.4 and have installed RVM. Its been great so far, I really love the way it lets me manage having multiple versions of rails and ruby on the same machine without headaches! However, I don't want to have to install certain gems (such as passenger) for each setup. Is there a way to share gems between gemsets? I ha...

[Ruby] How to get HTML after onchange by Nokogiri?

Hello. I`ve trouble on have a HTML document after onchange function by Nokogiri. Of course, Mechanize lib can control that. but, sadly webpage which I want to control is jsp not HTML. Generated HTML showes as belows : form method = "post" name = "mysearchform" <select id = "hall_no" name = "hall_no" onchange = "document.mysearchform....

Overriding default Rails date_select

So what I'd like to do is to override the default date_select method (I'd like to make an 'optional / unspecified' date input). What I've tried so far is this: lib/overrides.rb ActionView::Helpers::DateHelper::DateTimeSelector.class_eval do def build_selects_from_types(order) select = '' order.reverse.each do |type| sep...

metaprogramming access local variables

class Foo def initialize bar = 10 end fiz = 5 end Is there a possibility to get these local values (outside the class) ? ...

How can I get an ordered list of middleware in use in a generic rack application?

The functionality I am looking for is similar to the rake middleware command in Rails, except for a generic rack application. ...

Programming a distributed application written in C#, Ruby and Java using XML-RPC

Hello everyone, I am tasked with writing a distributed event managing tool where each client, either a Ruby, C# or Java Client, synchronises all changes with a list of registered clients. I have to use XML-RPC to achieve the goal. My team and I have written up an XML-RPC client and server in each language and will provide the relevant s...