ruby

How to retrieve values from a column called "object_id" in ActiveRecord?

I need to access a legacy relational database via ActiveRecord and that database uses a column named "object_id" as a primary key in a table. Most things work but when I try specify a custom SQL query for an association (see below) ActiveRecord respectively the Ruby interpreter always retrieves the object_id of the Ruby base "Object" ins...

rails caching with money gem (eu_central_bank)

I found this add-on for the Money gem which updates from the ECB European Central Bank (updates its rates every 24 hours) but I'm unsure how I should go about caching in my rails app which uses multiple currencies. http://github.com/RubyMoney/eu_central_bank eu_bank ||= EuCentralBank.new eu_bank.update_rates #Rails.cache.fetch('rates',...

Ruby on rails msvcrt-ruby191.dll problems on XP

I am trying to run Rails3 on XP Profesoinal and following the tutorial here http://railstutorial.org and am receiving the following errors all the time, even trying to return static pages. The message is the procedure entry point rb_str2cstr could not be located in the dynamic link library msvcrt-ruby191.dll Also, the page gives a runti...

Rails - How do I run a loop inside of a mailer?

So it turns out mailers hate loop inside of them. So here's my loop. - for ["love", "hate", "war"].each do |f| = f Which returns this went sent through actionmailer in rails 2.3.5 : promotion_reminder.html.haml:17: syntax error, unexpected ';', expecting tCOLON2 or '[' or '.' ...ry_temp));}\n", 0, false);end;_hamlout.push_text(" ...

text to html script

Does anyone have or know of a Ruby script that converts text to html? Example: I have a file that contains the following text: Host Name Info1 Line1 Info2 Line2 I want to have ruby convert it to the following html output Host Name Info1 Line1 Info2 Line2 I tried running RedCloth but got the following error: The progr...

Is this ruby metaprogramming abuse?

I am new to Ruby, and have a gem that I am making to interact with a JSONRPC API and basically all calls and responses are similar enough, that every API call can be handled with one function, like: Module::api_command('APINamespace.NamespaceMethod') but I would like to also (for convenience sake) be able to do: Module::APINamespace.N...

How do you use an attr_accessor in a select form?

I am trying to capture the identity of a gallery so that I can create a form based around that particular gallery. So I put together a select form, and threw an attr_accessor in my controller. But its failing from all sorts of directions, and I figure its a problem with my syntax. Any whiz's know this? model attr_accessor :existing_g...

Avoiding, in general, "undefined method 'some_method' for nil:NilClass" in Ruby

Ruby's duck-typing is great, but this is the one way that it bites me in the ass. I'll have some long running text-processing script or something running, and after several hours, some unexpected set of circumstances ends up causing the script to exit with at NoMethodError due to a variable becoming nil. Now, once it happens, it's usua...

ruby on rails :open flash stacked area

does anyone know if open flash plugin for rails supports stacked area chart could anyone point me to a working example of stacked area/area chart thx ...

Ruby gem Stream API like twitter

Is there any gem for ruby (i want to use it in a rails app) that does somethink like Twitter Stream API. Keep the http conection opened and send information in real time based in a query or events. ...

daemon spawn : gem_original_require : no such file to load --daemon-spawn (Load Error)

I am trying to run daemon process using daemon-spawn gem. Here is the code for delayed_delta daemon process #file - script/dj #!/usr/bin/env ruby # -*- ruby -*- require 'rubygems' require 'daemon-spawn' RAILS_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..')) class DelayedJobWorker ENV['MIN_PRIORITY'], :max_prior...

Ruby iterator for non-seekable stream

I want to read data records from a non-seekable stream in Ruby. I want to leave it up to the user whether the current record should be skipped or read. Usually you would include Enumerable and provide the necessary methods for it to have an iterator in Ruby, but in my case data can be skipped and only one iteration is possible, so I'm no...

Raise event in C# from external application?

Is there a way to raise an event in C# from an external application? In particular from Ruby? I have need to cause something to happen in C# from a rails application. ...

Help optimizing ActiveRecord query (voting system)

I have a voting system with two models: Item(id, name) and Vote(id, item_id, user_id). Here's the code I have so far: class Item < ActiveRecord::Base has_many :votes def self.most_popular items = Item.all #where can I optimize here? items.sort {|x,y| x.votes.length <=> y.votes.length}.first #so I don't need to do anything ...

FasterCSV importer to DataMapper model - No rows inserted

I have a model (called Test): property :id, Serial property :title, String, :length => 255, :required => true property :description, String, :length => 255, :required => true property :brand, String, :length => 255, :required => true property :link, String, :length => 255, :required => ...

Very simple Ruby GServer leaking memory

I've got the following Ruby script: class Server < GServer def initialize super(10001) end def serve(io) while true io.puts `ps -o rss= -p #{$$}`.to_i end end end server = Server.new server.start while true sleep 10 end When I open a connection to the server, it shows increasing memory usage over ...

ActiveRecord > MySQL Adapter > Case Sensitivity

I am working with a MySQL database that has capitalized table/field names like Users, Institutions, etc. Because the operating system of the database host is Linux, identifiers (like the table names) are treated as case sensitive. So, failing to capitalize a table name will result in a table does not exist error. The problem I am trying...

Can't puts out multiple lines

The following code opens a text file does a little regex to match names and numbers. I do an IF so that I only match numbers greater than 0. When I try to puts the name and number, I only get the numbers and the name have become nil. If I puts the names (variable a) before the if statement, it is there. What am I doing wrong? nf = File....

Rails - Best-Practice: How to create dependent has_one relations

Could you tell me whats the best practice to create has_one relations? f.e. if i have a user model, and it must have a profile... How could i accomplish that? One solution would be: # user.rb class User << ActiveRecord::Base after_create :set_default_association def set_default_association self.create_profile end end Bu...

How should I use git submodules to share code between Heroku apps?

I have a few Rails 3 apps deployed to Heroku that need to share some business logic. Apparently, although Heroku's Bundler support is pretty solid, it can't yet pull from a private Github repo. So instead I'm building a couple of gems, vendoring them into each app, checking them into git, and pushing them up with the rest of my code. Th...