ruby

Creating on-demand, print-quality PDFs (preferably in Ruby if feasible)

Main-Question What's your fast and reliable (as in "stable") solution to create on-demand, newspaper-like (as in "using advanced layout or typesetting") PDFs out of an application on a Linux server? Therefore: No, HTML2PDF is not the solution I'm looking for. ;-) Bonus-Question And if it's not Ruby-based: Is there a way to steer ...

Contextual ActiveRecord Model filtering

Throughout our site there's a common model, let's say Video, that has a number of attributes like private/public/pending, downloadable, etc. Based on the controller, action, request parameters and current user, we want to filter out particular videos from display. For instance, on the homepage we only want to show videos that are public...

How can I efficiently extract repeated elements in a Ruby array?

I have an array like [1,1,1,2,4,6,3,3] and I would like to get the list of repeated elements, in this case [1,3]. I wrote this: my_array.select{|obj|my_array.count(obj)>1}.uniq But it is tragically inefficient (o(n²)). Do you have a better idea? If possible concise. Thanks ...

Why C# is not dynamic language?

I heard on some podcast that C# is not dynamic language, but Ruby is. I searched online to understand why, but no success. So here is my question; what is “Dynamic Language”? Is this means there’s a static language? Why C# is a dynamic language and what other languages are dynamic? If C# is not dynamic, so why Microsoft is pushing is ...

Ruby-OpenID: Requiring email-address from OpenID provider

I'm playing with the authlogic-example-app and I'm failing to get the email address from the OpenID provider (in my case: Google and Yahoo) when I register a user, resp. I get an empty response instead of an email address (check the comments in code below). This is how my user model looks like (everything else looks like the "with_openi...

Parsing in Ruby (on Rails)

I want to write a Rails app to assist me with my online Poker. I play on PokerStars, and there is text data available for each hand that is played. The format it comes in is this: PokerStars Game #27457662450: Tournament #157033867, Freeroll Hold'em No Limit - Level IV (50/100) - 2009/04/24 20:39:44 ET Table '157033867 830' 9-max Seat ...

Do you have to do duplicate gem installs for JRuby & MRI?

I have JRuby and Ruby (MRI) installed. It seems that I need to install gems twice - once for each of these platforms. Is this necessary or am I doing it wrong? After I installed the rails gem for MRI, should I have pointed JRuby to it, or was it necessary for me to also call: "jruby -S gem install rails" ...

Why does the sqlite 1.2.3 gem install correctly for MRI but not for JRuby?

If I call: gem install sqlite3-ruby --v 1.2.3 it works for MRI but if I call: jruby -S gem install sqlite3-ruby --v 1.2.3 it says it's trying to build a native extension (for Windows) and fails. Why are JRuby and MRI different in the way they treat gems? ...

How do you split an email on lines?

I am retrieving emails using the Fetcher plugin for Rails. It is doing a fine job. But I am trying to split the body of the email on newlines but it appears that it is only one really long line. What is the best way (in Ruby) to split an email up into multiple lines? ...

Is there a shorter way to require a file in the same directory in ruby?

Is there a shorter way to require a file located in the same directory (as the script being executed)? require File.expand_path(File.dirname(__FILE__) + '/some_other_script') I read that require "my_script" and require "./my_script" will actually load the script twice (ruby will not recognize that it is actually the same script), and ...

Ruby metaprogramming online tutorial

I have just started to learn Ruby and got a good take on the basics. I keep hearing that one of the cool things that Ruby does very well is metaprogramming, but none of the tutorials I've read cover this. Searching Google I can only seem to find paid for ruby metaprogramming screen casts. So, where can I find a good Ruby metaprogramming...

One-Click install for Ruby/Rails/SQLite?

I'm really excited to start programming in Ruby with the Rails framework; I've read great things about Ruby on Rails! I've gotten myself a couple of books, thumbed through a few tutorials, read some forum threads, but I'm already stuck on Step One: Installation. I guess I'm more used to the One-Click install local environments of MAMP. ...

Ruby regex to remove newlines from specifc HTML tag?

Hi everyone, Sorry I'm really bad at regexes, I finally hacked osmething to work in ruby. I'd appreciate if someone can instruct the proper way of how to do this: I basically wanted to remove all \n when it appears within ul tags. while body =~ /<ul>.*(\n+).*<\/ul>/m body =~ /<ul>(.+)<\/ul>/m body.gsub!( /<ul>(.+)<\/ul>/m, ...

I don't want to learn PHP. Should I avoid learning it?

I've been programming in Ruby on Rails for a year now. I looked at some of the PHP code of WordPress and its e-Commerce plugin. This is not going to sound professional, but it looked disgusting. Having only done development in an MVC framework, I can't imagine how is it possible to work without those patterns. There also seems to be no a...

RoR: how do I create a "valid signup code" lookup?

Hi, I want to be able to give codes to potential users in the form of email links (e.g. mysite.com/signup?beta=rapunzel) When someone clicks on the link, it populates a hidden_field with the value (will just using :params[:beta] work?) Then before it creates the user it validates by checking against another table where I have differen...

ruby: can I have something like Class#inherited that's triggered only after the class definition?

#inherited is called right after the class Foo statement. I want something that'll run only after the end statement that closes the class declaration. Here's some code to exemplify what I need: class Class def inherited m puts "In #inherited for #{m}" end end class Foo puts "In Foo" end puts "I really wanted to have #inherit...

Issues concatenating to an array constant for options_for_select

Hello, I have the following code: <%= select_tag :role, options_for_select(Project::COMPANY_ROLES.concat(['Other...']), @relationship.role) %> For some reason it concatenates "Other..." to COMPANY_ROLES but saves this past the view that was loaded. 1st Run = 1 option of "Other..." 2nd Run = 2 options of "Other..." 3rd Run = 3...

Viewing a Ruby on Rails script in my native browser

I'm new to developing in Ruby and have mostly been using irb to experiment with code. For longer scripts, it would be helpful to be able to run them in my native browser (similar to how I run php scripts through MAMP). I believe there is a way to do this using localhost:3000 but I have not been able to get it to work. So my question i...

How to prevent backgroundrb from starting multiple copies of the same task?

Say, I have a worker that's set up to run every 15 minutes using the cron scheduling feature of backgroundrb. Then, say, if a single instance of the worker takes longer than 15 minutes to run, I don't want a second worker to be started in paraller by backgroundrb. How do I achieve that? ...

Evaluating :dependent => :destroy

In Rails 2.2.2 (ruby 1.8.7-p72), I'd like to evaluate the impact of destroying an object before actually doing it. I.e. I would like to be able to generate a list of all objects that will be affected by :dependent => :destroy (via an object's associations). The real problem I'm trying to solve is to give a user a list of everything tha...