ruby

Ruby: how can I get the name/version of the Yaml parser I'm using? Where can I get yaml4r?

I've been reading the YAML docs on http://yaml4r.sourceforge.net/doc/ There is an example: puts [[ 'Crispin', 'Glover' ]].to_yaml( :Indent => 4, :UseHeader => true, :UseVersion => true ) It's supposed to emit a string with a "%YAML:1.0" tag in it---when I run it I don't get that at all. Is there a way to tell which library I'm actua...

Automatic text marking by regular expressions. Newlines problem.

Hello, i'm having some troubles with regular expressions in ruby. I need to categorize some files that have the first line followed by two newlines, like in this example: GIOVIANA Si scrivono miliardi di poesie sulla terra ma in Giove è ben diverso. Neppure una se ne scrive. E certo la scienza dei gioviani è altra cosa. Che cosa sia ...

Multiple rack apps on nginx + passenger, one as root, the other not...config help

So I've got two apps I want to run on a server. One app I would like to be the "default" app--that is, all URLs should be sent this app by default, except for a certain path, lets call it /foo: http://mydomain.com/ -> app1 http://mydomain.com/apples -> app1 http://mydomain.com/foo -> app2 My two rack apps are installed lik...

Evaluating string templates

I have a string template as shown below template = '<p class="foo">#{content}</p>' I want to evaluate the template based on current value of the variable called content. html = my_eval(template, "Hello World") This is my current approach for this problem: def my_eval template, content "\"#{template.gsub('"', '\"')}\"" # gsub to...

net/imap from behind a proxy

I would like to use the net/imap library in ruby behind a authenticated proxy, I was starting to dig in and I'm wondering if there is a way to do this already or if I need to make my own version of the net/imap library that supports a proxy? ...

How do I show information attached to a model from another model?

I have just completed the introduction guide to RoR: http://guides.rubyonrails.org/getting_started.html. It's a great guide and everything works. I am trying to extend it a little bit by SHOWING tags in the Post view. (The guide sets it up so that you can add tags while adding a post even though Tag and Post are different models). This...

Using rubyzip to add files and nested directories to a zipoutputstream

Hi, I'm struggling with getting rubyzip to append directories to a zipoutputstream. (I want the output stream so I can send it from a rails controller). My code follows this example: http://info.michael-simons.eu/2008/01/21/using-rubyzip-to-create-zip-files-on-the-fly/ When modified to include directories in the list of files to add I...

Display logfiles in realtime using ruby

I need to display logfiles in real time to user webpage using ruby/rails. Users should be able to see logfile steaming without refreshing the page. Logfiles may not always be in the same machine which runs rails. Is it possible in ruby/rails ?. ...

Is there a Python equivalent of Ruby's 'any?' function?

In Ruby, you can call Enumerable#any? on a enumerable object to see if any of its elements satisfies the predicate you pass in the block. Like so: lst.any?{|e| pred(e) } In Python, there's an any function that does something similar, but on a list of booleans. Of course, for a reasonably-sized list, I'd just do: any(map(pred,lst)) ...

Where to put methods that do simple date formatting

I have two models, BusinessHour and StaffHour that both inherit from Hour. In the BusinessHour and StaffHour models I do a 'find' to retrieve requested hours. After that I need to format each time to a specific format, which I have a method for. I'm trying to figure out where to put that method. It sort of seems like it would go in a H...

Using RackDAV to expose a webdav directory in a Rails app, how can I map the directory to serve up?

I am using RackDAV, and it's GREAT! http://github.com/georgi/rack_dav However, the only way I can get it integrated into my Rails app is to modify my server startup file, which I copied from /vendor/rails/railties/rails/commands/server file! Obviously not great. I have this working: app = Rack::Builder.new { use Rails::Rack::LogT...

how to go from beginner level to proficient level with ruby on rails?

i need some advice since i have read 4 books for beginners in ROR.should i contribute to open source projects?how ?where can i find project that are easy enough to improve my skills. thank you. ...

Ruby on Rails custom Observer

Could anyone advise how to use custom observer or events/callbacks in Ruby on Rails? I have tried both these posts: http://www.mutuallyhuman.com/2009/1/6/using-custom-activerecord-events-callbacks and http:// alexkira.blogspot.com/2008/10/custom-observer-callbacks-in-rails.html none seems to be working. On the second post, I put Alex ...

Process first n-files in the directory

I have a function which prosecces first N files in the direcory: def restore(cnt) $LOG.debug "store_engine : restore tweets from cache (cnt = #{cnt})" result = TweetCollection.new Dir["cache/*"].each do |path| cnt = cnt - 1 File.open(path) do |f| result.append(Tweet.construct(:friends, :yaml, f.read)) end i...

Rails Math.radians

I need Math.radians() function and can not find it. Thx for help. radians=(angle/180)* Math::PI ...

Use rspec to test C/C++ program

Hi, Is Rspec ruby/rails specific? Is it possible to use it as a test framework for C/C++ program? ...

coercing nil into a number

What is happening here?? irb(main):001:0> a= nil => nil irb(main):002:0> b = nil => nil irb(main):003:0> a => nil irb(main):004:0> a+b NoMethodError: undefined method `+' for nil:NilClass from (irb):4 from :0 irb(main):005:0> if a.nil? or b.nil?; a,b=0;end; irb(main):006:0* c = a+b TypeError: nil can't be coerced into Fixnum ...

Using 'return' in a Ruby block

I'm trying to use Ruby 1.9.1 for an embedded scripting language, so that "end-user" code gets written in a Ruby block. One issue with this is that I'd like the users to be able to use the 'return' keyword in the blocks, so they don't need to worry about implicit return values. With this in mind, this is the kind of thing I'd like to be...

CLI-Based "V" in Rails MVC?

Having a hard time getting any useful results from various searches on this concept -- probably because it's a. Wrong and/or b. obscure. Essentially, though, I'd like to write an application which works as either a normal web app or with a command-line interface. I've done this in the ancient past for sysadmin-y stuff using Perl, but t...

rails validation contigent on multiple elements

I've been using accepts_nested_attributes_for for a few different models and I've got an odd situation. I can skip creation blanks thru the top model, and I can validate_presence of individual records thru the bottom, but is it possible to do a most complex validation on a set of records? I have the models Rooms and Rates. Rooms has_m...