ruby

Exposing console apps to the web with Ruby

I'm looking to expose an interactive command line program via JSON or another RPC style service using Ruby. I've found a couple tricks to do this, but im missing something when redirecting the output and input. One method at least on linux is to redirect the stdin and stdout to a file then read and write to that file asynchronously wit...

Ruby on Rails ActiveRecord: pluralization

I'm new to Rails, so forgive my ignorance of ActiveRecord. One of my models is named "campus". I ran the migration and it pluralized everything except "campus". I thought that was lame so I added the code to the environment config to leave everything singular. I deleted the tables, manually edited the migration files to use singu...

Error happens when I read items in DataMapper

class List include DataMapper::Resource property :id, Serial property :name, String property :items, String end List.auto_migrate! get '/:id' do @list = List.all(:id => params[:id]) @items = @list.items erb :show end I get undefined method `it...

Having Issues with Curb gem on Mac Snow Leopard

This has consumed hours of my time. in the console i run: require 'curb' i get the error: LoadError: dlopen(/usr/local/lib/ruby/gems/1.8/gems/taf2-curb-0.5.4.0/lib/curb_core.bundle, 9): no suitable image found. Did find: /usr/local/lib/ruby/gems/1.8/gems/taf2-curb-0.5.4.0/lib/curb_core.bundle: mach-o, but wrong architecture - /usr/lo...

Having issue while using soap4r, unable to add namespace, encoding style to soap envelope.

Hi, I am having problems with one of the soap service I'm using. I am using soap4r for consuming the soap service. But somehow they are expecting something else than what I am sending. This is what I'm sending:<?xml version="1.0" encoding="utf-8" ?> <env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:env="http://schemas....

Check if a string is capitalized in Rails

I'm looking to check if a string is all capitals in Rails. How would I go about doing that? I'm writing my own custom pluralize helper method and I would something be passing words like "WORD" and sometimes "Word" - I want to test if my word is all caps so I can return "WORDS" - with a capital "S" in the end if the word is plural (vs. "...

No memory available to program now: unsafe to call malloc

Hi, I'm new to rubycocoa and i'm implementing an nstableView. I have saved all data to a plist file. Now when i tried to reload my data to the tableView my program becomes unresponsive and when quit it, it gives the message: No memory available to program now: unsafe to call malloc. My program stops somewhere in this method: def tableV...

Can I inherit an erb template?

Is there any way to have a template inherit another template? I'm not using Rails. ...

Ruby thread newbie,something went very wrong.Can you help me spot what it is?

In a thread, I'm doing the following: builder_thread = Thread.new do FileUtils.cp_r(folder,dest) io_object = IO.popen(command) Thread.current["output"] = "" Thread.current["pid"] = io_object.pid Thread.current["basedir"] = dest io_object.each { |out| Thread.current["output"] += out } end and this works ok, when...

Questions about Scala from a Rubyist

I have recently been looking around to learn a new language during my spare time and Scala seems to be very attractive. I have a few questions regarding it: Will not knowing Java impose a challange in learning it? Will it be a big disadvantage later on? ( i.e How often do people rely on Java-specific libraries? ) How big of a differe...

aggregate conditional has_many rails association

I'm not sure if this is feasible or even preferable But I'd like to build a has_many relationship or a conditional named_scope type relationship to ease my pain into one simple relationship instead of two. Currently I have two models which basically contain the same information and belong to the same Model rooms thru the same key room_...

Ruby on Rails Forms: how to create a CheckBox Table (or List)

What's the best way to create a related set of checkboxes in Ruby on Rails? In the ToscaWidgets library used by Turbogears you can do the following: twf.CheckBoxTable('arbitrary_numbers', num_cols=5, options=['1','2','3','4','5','6','7','8','9','10']), This generates 10 labeled checkboxes in two rows of 5 checkbo...

Ruby HTTP breaks when server is off

Net::HTTP gives a "undefined method `closed?' for nil:NilClass" if the server is down... is this a standard response that I can trust? Shouldnt it raise a Net:* exception? Regards ...

How does one determine console character width from ruby program?

I want to print columnar output from a ruby program, but in order to take full advantage of the available screen space, I need to determine the character width of the terminal the program is running in. How does one do this? ...

has_many through checkboxes

Given the following models class Feed < ActiveRecord::Base has_many :alerts , :dependent => :destroy has_many :users , :through => :alerts end class Alert < ActiveRecord::Base belongs_to :user belongs_to :feed has_and_belongs_to_many :alerttypes end class Alerttype < ActiveRecord::Base has_and_belongs_to_many :aler...

Loading a marshaled Ruby object in C#

When you run the command gem outdated -V, the output of the command displays something similar to this: GET http://rubygems.org/latest_specs.4.8.gz 302 Found GET http://production.s3.rubygems.org/latest_specs.4.8.gz 200 OK This will send you a gzip file that contains another file called latest_specs.4.8 which you can Marshal.load with...

Testing rails controller with rspec

Hi, I'm new to rails and I'm trying to test a controller with rspec. My first test is when the show action is invoked, it should lookup a Category by url. The problem is when I add the stubbing code, I get the following error: undefined method `find' for # my test looks like this: require 'spec_helper' describe CategoriesController ...

Recursive routes in Rails

Is is possible to create a recursive route in Rails? I have an application, which allows a admin to create pages. The page model is a nested set and so each page has a parent_id hence the pages are structured in trees. The page model also uses the Friendly ID plugin to provide slugs for each page. When a user browses the site I would l...

Active Record: ordering finds and also returning nulls

I want to find a ordered list of runners by their results. models class Race < ActiveRecord::Base has_many :runners, :dependent => :destroy end class Runner < ActiveRecord::Base belongs_to :race has_one :result, :dependent => :destroy end class Result < ActiveRecord::Base belongs_to :runner end trying to use something like t...

Is "extend self" the same as "module_function"?

extend self and module_function are two ruby ways to make it so you can call a method on a module and also call it if you include that module. Are there any differences between the end results of those ways? ...