ruby

Create paperclip attachment from rmagick image

Hi, I have a problem to find a way to save an image created with RMagick in a paperclip attachment. imageList = Magick::ImageList.new imageList.new("images/apple.gif", "images/overlay.png") ... picture = imageList.flatten_images I am in a model that have an attached file has_attached_file :picture, :url => ..., :path => ... ...

Ruby, does it allow Cartesian product constructors?

As the title states, does Ruby allow Cartesian product types? I can't find anything on it anywhere. Thanks ...

Rails3 - why my view loading times are so long?

So one week ago I started to move my old app written in Rails 2.3.5 to new 3.0. Unfortunately, I found out that some of the views are loading surprisingly slow. Example: Rails 2.3.5 Ruby 1.8.7 -> WEBrick: Completed in 297ms (View: 143, DB: 40) Rails 3.0.0 Ruby 1.8.7 -> WEBrick: Completed in 3081ms (View: 261, ActiveRecord: 108) Rails ...

Bloomberg Server API and Ruby/Python

Im looking to write a new application in ruby/python which uses a feed from bloomberg and am stuck trying to find any documentation for using (or even setting up) Bloomberg Server API with either of these languages. Does anyone have any good links to tutorials for this or maybe some boilerplate code to get set up? Or is it best to just ...

Ruby Mysql Crashing

My ruby code crashes on this code puts "one" con = Mysql.real_connect('localhost', 'user', 'pass', 'database') puts "two" It outputs one but not two?? Why isn't it executing any further ...

How to write fast XML parsers in ruby?

I am using Nokogiri which works for small documents well. But for a 180 kb html file I have to increase the process stack size (via ulimit -s) and the parsing takes a long time. Let alone xpath queries. Are there faster alternatives available using a stock ruby 1.8 distribution? I am getting used to xpath, but the alternative does not ...

Suggestions for next language to learn

I figured its time to start learning another language, but I can't decide between Ruby and Python (I'd like to start using Rails or Django). Which one do you think would be both most helpful and fun to learn, and if possible, could you give me some sites/links that would help me get started? If you think there's another language that wo...

Specifying Content Type in rspec

I'm trying to build an rspec test that sends JSON (or XML) via POST. However, I can't seem to actually get it working: json = {.... data ....}.to_json post '/model1.json',json,{'CONTENT_TYPE'=>'application/json'} and this json = {.... data ....}.to_json post '/model1.json',json,{'Content-Type'=>'application/json'} a...

Testing redirect after login with Devise

I've followed the recommendation from the Devise github pages for this: http://github.com/plataformatec/devise/wiki/How-To:-Redirect-to-a-specific-page-on-successful-sign-in Now this works great, but how would you test that you have this behavior now? ...

Rails 3 model associations

I am making a simple BBS system with ruby on rails3. 3 main modesl are Members/Categories/Articles. Article belongs to Members/Categories, (member_id/category_id columns in db table) and each member/category 'has_many' articles. When a specific user tries to write an article, I tried it by def new @article = current_member.article...

image upload problem. Uploaded file size 0 bytes

I am trying to upload an Image. The image file gets created but the size of the file is 0 bytes. Here is the code in controller name = params[:comparison][:image1].original_filename name_content_type = params[:comparison][:image1].content_type directory = "public/images" path = File.join(directory, name) file = File.open(path, "wb") ...

Connection Issue while using Jasmine Javascript Testing Framework

I am having an issue using Jasmine on Ubuntu when trying to run the example javascript specs through Selenium using the "rake jasmine:ci" command. I will periodically get a "Connection refused" error when net/http is trying to connect to the port where Selenium is running. An example the start of the backtrace I get is: Waiting for jasm...

Overriding "initialize" in Ruby Ncurses::WINDOW class?

I have following code to try and alter the default Ruby Ncurses behavior: #!/usr/bin/env ruby require 'logger' require 'rubygems' require 'ncurses' class Ncurses::WINDOW def initialize( height, width, starty, startx ) w = super( height, width, starty, startx ) w.clear w.move(0,0) w.addstr('first psot') ...

How to get an HTTPS request with SSL client cert to work with Ruby EventMachine

I am trying to access an HTTPS web service that uses SSL cert authentication using Ruby EventMachine but I am not getting it to work. I have written the following simple code block to test it end-to-end: require 'rubygems' require 'em-http' EventMachine.run do url = 'https://foobar.com/' ssl_opts = {:private_key_file => '/tmp/priv...

Is there a Ruby on Rails based torrent tracker?

I'm looking for a torrent tracker written in Ruby on Rails (TBDev.net style or so). Is there a ready made package? Another option: Is there a robust torrent tracker software that can act as a backend for which I can write a RoR front end? ...

Ruby require "no such file to load" error yet clearly in path.

I've been trying to get a ruby file to require another ruby file and I feel like I'm going crazy. My setup is as follows Two files in '/raid1/ruby-code/benchmark/' CommandRunner Benchmarker Benchmarker is the main program at this point and wants to require CommandRunner, I've tried a bunch of different things and none of them work....

Using class function from the lib directory in rails

Hey! I am creating a rails3 application and I want to create a class that handles string formatting, so I made a class called FormatUtilites.rb in the lib directory but whenever I try calling it from somewhere else in my app I get this error: ActionView::Template::Error (uninitialized constant ActionView::CompiledTemplates::FormatUtil...

ruby: overriding strings' methods returning nil (strip!, upcase!, downcase!, capitalize!, chop!, chomp!, delete!, gsub!)

Those stupid 'string'.method! returning nil instead of self in ruby - can be easily overriden: class String ['strip!', 'upcase!', 'downcase!', 'capitalize!', 'chop!', 'chomp!', 'delete!', 'gsub!'].each do |meth| orig_meth = "orig_#{meth}" alias_method orig_meth, meth define_method(meth) do |*args| ...

In Ruby, is there a difference between %w(x y z) and %w[x y z]?

In Ruby, is there a difference between %w(x y z) and %w[x y z]? I see both in docs and examples, and both seem to work for me. ...

Can you add a Class Method to the Core Module Class in Ruby?

Is it possible to add a core method to the Module class in Ruby? I want to do something like this (messed around with the idea yesterday, just whipped this together in a second): module MyModule base do has_many :something end end # implementation, doesn't work though... reason for the question Module.class_eval do def self....