ruby

Ruby: "do this task eventually"

I hope this question is clear enough -- if not let me know :) What API would I use when I want to write a procedure at runtime and then just run it eventually at low priority while continuing to do the important stuff right now? Example: link checker 1. I write a blog post with links represented by Link objects. I publish the post. 2. ...

Cleanup ActiveRecord field

I have model Article it has field title with some text that may contain some "magic" patterns. In some cases i need to process text in title and other cases i don't, but in last case i need to get string w/o that patterns. For example i have title value like "Something **very** interesting" and when i call @article.title i need to get c...

Ruby: How can I have a Hash take multiple keys?

I'm taking 5 strings (protocol, source IP and port, destination IP and port) and using them to store some values in a hash. The problem is that if the IPs or ports are switched between source and destination, the key is supposed to be the same. If I was doing this in C#/Java/whatever I'd have to create a new class and overwrite the hash...

Can I put some form of If..End blocks inside of a hash definition?

I am creating a web application to integrate with Chargify. I want to return a hash with customer_id set if the user has a customer associated with the account, and customer_attributes if a customer has to be created. Is there any way that I could do this with an if..end block inside of the hash definition. For example, I would be wanti...

Error loading Mongrel in Aptana Ruby Application on Vista

I'm brand new at Ruby. Trying to set up the first application/project using Aptana Studio. Here are my ruby and gem versions c:\>ruby -v ruby 1.9.1p378 (2010-01-10 revision 26273) [i386-mingw32] c:\>gem -v 1.3.6 I am seeing this error below while starting my ruby application. I'm developing on Vista (sucks, I know but am working on ...

Problem with multidimensional arrays in ruby.

ruby 1.8.7 (2008-08-11 patchlevel 72) [i586-linux] From script/console: >> pairs = Array.new(2).map!{Array.new(2).map!{Array.new(2, Array.new)}} => [[[[], []], [[], []]], [[[], []], [[], []]]] >> pair = Pair.first => #<Pair id: 39, charge_card_id: 1, classroom_id: 1, timeslot_id: 1, created_at: "2010-04-01 00:45:37", updated_at: "2010-...

How to run my script x times a day? (ruby on linux)

I want to run my ruby script x times a day (the number might change) on my linux box. What would be the best way to do so if I do not want it to happen at the same time? I want the time (hour and minute) to be random I was thinking of using at command. The script would be called by at in x hours/minutes or so and then the script would s...

Ruby Rack: startup and teardown operations (Tokyo Cabinet connection)

I have built a pretty simple REST service in Sinatra, on Rack. It's backed by 3 Tokyo Cabinet/Table datastores, which have connections that need to be opened and closed. I have two model classes written in straight Ruby that currently simply connect, get or put what they need, and then disconnect. Obviously, this isn't going to work long...

How to display image pointed by URL in Rails

HI, I have a image here http://power.itp.ac.cn/~jmyang/funny/fun4.jpg and I want to display it in my Rails site. How should i do that? EDIT: Well, guys , I understand the downvotes now. It is because it is too naive a qeustions:) Sorry, I know almost nothing about HTML tags before asking the question but thanks to Rails, even that I t...

about ruby range?

like this range = (0..10) how can I get number like this: 0 5 10 plus five every time but less than 10 if range = (0..20) then i should get this: 0 5 10 15 20 ...

Sintra app in a gem

I have a Sinatra application I've created and I'd like to package it as a gem-based binary. I have my gemspec and gem set up to generate a suitable executable that points to the my_sinatra_app.rb (which is executable) but the sinatra server never runs. Any ideas why and how to make it work? my_sinatra_app executable: #!/System/Library...

Find a set of common elements from a multi-dimensional array recursively

I have a multi-dimensional array: a=[[2,3,4],[1,3,4],[1,2],[1,2,3,4]] i've to compare all the 4 sub-arrays and get common elements.Next,take 3 subarrays at a time and get common elements.then take 2 sub arrays at a time and get common elements, in RUBY. ...

problem with installing mmangino-facebooker gem

Hello, I've problem like in title. I'm using ruby with Sinatra framework and trying to integrate my site with faceboook connect using frankie gem. Unfortunetly I'm getting dependencie error like that: Could not find RubyGem mmangino-facebooker (>= 1.0.2) When I try to install sudo gem install mmangino-facebooker I'm getting ...

Sinatra Set Settings (Ruby)

Using Sinatra in Ruby you can set the server's settings by doing: set :myvariable, "MyValue" and then access it anywhere in templates etc with settings.myvariable. In my script I need to be able to re-set these variables falling back to a bunch of defaults. I figured the easiest way to do this would be to have a function that perform...

Is there any way to hook the "controller" generator so it runs "rspec_controller"?

I want to make it so I can just type script/generate controller and it will run script/generate rspec_controller. How can I do this? ...

Rubyzip - possible to set extraction folder?

Hi. My problem is that I need to set the root extraction folder for a zip-file I`m generating by using Rubyzip. The zip-file will be opened in MS windows as an zelf-extractable. Is this option available in Rubyzip? Or is this a value that is stored in the windows registry and used by the integrated zip-functionality in windows? ~ Tord ...

Can a repeated piece of regular expression create multiple groups? Such as this example...

Hi guys, I'm using RUBY 's regular expression to deal with text such as ${1:aaa|bbbb} ${233:aaa | bbbb | ccc ccccc } ${34: aaa | bbbb | cccccccc |d} ${343: aaa | bbbb | cccccccc |dddddd ddddddddd} ${3443:a aa|bbbb|cccccccc|d} ${353:aa a| b b b b | c c c c c c c c | dddddd} I want to get the trimed...

Multi-lingual website and webby

Hi, Anyone know how to best implement a multilingual static site using webby? I would put content for the multiple languages in content/{lang}/{page}.txt for starters, any ideas on the rest? I've never used webby. Thanks, Max. ...

What is the quickest way to recursively add directories onto the $LOAD_PATH in ruby?

I'd like to slap everything in vendor/gems/gems/**/lib onto the load path. I've got a way to do it, but it just feels clunky. Right now, I'm doing it via: base = File.expand_path(File.join(File.dirname(__FILE__), "..", "vendor", "gems", "gems")) libs = File.join(base, "**", "lib") Dir.glob(libs) { |lib| $LOAD_PATH.unshift lib} I'm sure...

Ruby and jQuery -- $(document).ajaxSend() not modifying the params as expected

I cannot get jquery's ajaxSend (http://api.jquery.com/ajaxSend/) to properly modify the parameters. I have: $(document).ajaxSend(function(event, request, settings) { settings.data = $.deparam(settings.data); settings.data['random'] = new Date().getTime(); settings.data['_method'] = 'get'; settings.data = $.param(settings...