ruby

What is the correct way to load modules/classes from lib/ when using the config.threadsafe! option?

I've been working on getting our Rails 2.3.8 app running correctly under JRuby. Everything works great until I enable config.threadsafe! in order to achieve the concurrency that JRuby offers. This caused modules and classes in lib/ to no longer autoload. with config.threadsafe! enabled: $ ruby script/runner -e production 'p Sim::Sim200...

What does send() do in Ruby?

Can someone please tell me what send("{Model.find...}") is and does? ...

Good Way to Handle Many Different Files?

I'm building a specialized pipeline, and basically, every step in the pipeline involves taking one file as input and creating a different file as output. Not all files are in the same directory, all output files are of a different format, and because I'm using several different programs, different actions have to be taken to appease the ...

ActiveRecord serialization problem

I have a db column which is a serialized Hash: class Foo < ActiveRecord::Base serialize :bar end When I store a hash inside of bar that is a few levels deep, the deeper levels do not seem to properly deserialize when I need them. Objects one level deep get deserialzed just fine. However, objects 2 or more levels deep remain YAML cl...

approve the class type of one object in rails

Hi there, I have a simple question about rails syntax: How can I find out to which class a object belongs? I try to do someting like: if class(object) == MyClass Thanks Maechi ...

How to load a partial inside of a partial?

I'm trying to fire an AJAX request when my page loads. I'm guessing this would be best from my controller. First I open a new page.. def text_tabs_nav end This page has the ability to load by AJAX two different partials. I want to load one of them on default. So I thought maybe this .. def text_tabs_nav respond_to do |format| ...

One liner nested hash creation in ruby? (I come from perl)

I am a perl person and I have made hashes like this for awhile: my %date; #Assume the scalars are called with 'my' earlier $date{$month}{$day}{$hours}{$min}{$sec}++ Now I am learning ruby and I have so far found that using this tree is the way to do many keys and a value. Is there any way to use the simple format that I use with pe...

how to fetch all msgid and msgstr from .pot file.

I have a app.pot file. And i want to fetch all msgid and msgstr from that file. Is there any specific and proper way to do that?? ...

Rails: download file with "Open With" option

I'm running Rails 2.2.3. I have a controller that I am using to manage uploading and downloading files. I have successfully linked to files on the view to allow a user to download, but when the download dialog box opens, it only shows a Save File option. I'd like to have the "Open With" option available as well. I'm using Firefox 3.6 on ...

Disabling Ruby 1.9.x's YARV compiler

There is a very noticeable difference in application initiation time between running my specs from the command line with ruby 1.9.x vs. 1.8.7. My application initiates much faster with ruby 1.8.7 than with ruby 1.9.1 or 1.9.2. The application initiation difference is approximately 18 seconds. It takes about 5 seconds for my app to ini...

Rails - YAML load returns false

Hey, I am storing an object in a table with YAML dump but when I go to get it back with load it returns false when I use .to_s require "yaml" @candidates = YAML::load(serialized_object.to_s) if I do it without .to_s I get an "instance of IO needed" error serialized_object.inspect shows this --- "[#<SearchIndex data: \"--- \\n- 1\\...

Using ruby for scripting

I want to use ruby script for installing all the necessary things for a working rails environment. I wonder how I could run `sudo aptitude install <appname>` and actually see the output generated just like if I ran that line in the command line. And when I am prompted to type in something, then I can do that. Is this possible? Tha...

Nokogiri/Ruby array question

Hello, I have a quick question. I am currently writing a Nokogiri/Ruby script and have the following code: fullId = doc.xpath("/success/data/annotatorResultBean/annotations/annotationBean/concept/fullId") fullId.each do |e| e = e.to_s() g.write(e + "\n") end This spits out the following text: <fullId>D00...

Rack::Session::Pool with Sinatra

I have a Sinatra webapp I've built using enable :sessions where I access my session data with session[:mything]. I now want to store data on the server side (ie. with database based sessions) and I can't figure out how to use Rack::Session::Pool, which appears to be the thing I need to use. How do I o about converting my webapp for use...

To change directory inside a ruby script?

I want to create a new rails application and fire up the rails server for that application, everything from a ruby script. My code look like this: #!/usr/bin/env ruby system "rails new my_app" system "cd my_app" system "rails server &" However, when running "rails server &" the path is not in the my_app folder, but in the parent fold...

Rails params parsing, escaping needed?

I'm currently using Jquery to serialize() a form, which contains a textarea, and POST it to Rails. This works successfully in most cases, unless the textarea contains a line in quotes, on its own. If such a line exists Rails parses the contents between the quotes of that line as the params variable rather than the entire contents of th...

win32ole gem for jruby

Hi jruby mavens, I'm trying to install jruby gem from http://github.com/bpmcd/win32ole . it seems that standard jruby -S gem install win32ole doesn't work. I'm ruby noobie, and so far I understand that this package is not a gem? Am I correct? Do I need to build it? If yes, could you direct me to the docs that explain how to proceed...

Extended Log File Format Parser in Ruby

Hi, I'm looking for a ruby parser for the W3C Extended Log File Format. http://www.w3.org/TR/WD-logfile.html Ideally it would generate a multidimensional array based on the fields in the log file. I'm thinking something similar to how FasterCSV (http://fastercsv.rubyforge.org/) handles CSV files. Does anyone know if such a library ex...

Using Ruby's gsub with a string containing "\0"

I'm having trouble using gsub correctly: Given this code: "replace me".gsub(/replace me/, "this \\0 is a test") The result is: "this replace me is a test" But what I am expecting is: "this \0 is a test" How do I use gsub to get the result I want? ...

Ruby gem (FFMPEG) "uninitialized constant"

When trying to use the FFMPEG gem on Mac OS X 10.6, ruby throws a NameError exception like so: NameError: uninitialized constant FFMPEG My code is rather simple: class Parser def initialize(file) require 'ffmpeg'; @video = FFMPEG::InputFormat.new(file); end end I have ruby 1.9.1p378 (2010-01-10 revision 2627...