ruby

Ruby on Rails: Error when running a rake task from initializer file

I have the file config/initializers/custom.rb In the file, there is only one line: `rake thinking_sphinx:start` I thought this was supposed to just execute the line like when typing it from a command line. With this line of code, when I run "ruby script/server", the server freezes and outputs no error messages. Am I missing somethi...

Why does active_record break the behavior of Ruby's trap and how do I work around it?

In the last couple of days, I've been trying to get a solution to an active_record issue that has been plaguing me. Posts on railsforum and stackoverflow have turned up completely dry. The length and level of detail in those posts may have dissuaded commentors, so I'm trying again - in brief. Under windows, the trap behavior is normal...

Using Javascript OpenID Selector with Rails

Based on this article, it seems like SO is using Javascript OpenID Selector (JOIS) to handle OpenID logins in its "view". I love the simple interface and I would like to use it in a Rails project. I know that RPX would probably be the easier choice, but I'd like to build this on my own. Can you help me find answers to a few question...

Data Driven Testing with Ruby's Test::Unit for Selenium

I'm pretty new to both Ruby and Selenium and I'm just trying to figure out the best way to build my test harness. I'm using Rake, Rake::TestTask, and Test::Unit to power this. I have a suite that I'd like to run once for each browser/os combination. I can't figure out how to parameterize my tests though, something I've become accustomed ...

Ruby monitor segmentation fault

I followed the example from http://www.ruby-doc.org/stdlib/libdoc/monitor/rdoc/index.html and modified the code a bit: require 'monitor.rb' buf = [] buf.extend(MonitorMixin) empty_cond = buf.new_cond producer = Thread.start do # producer line = "produce at #{Time.now}" #while line buf.synchronize do puts "==> #{line}" buf.pu...

Pulling stats out of a text

I'd like to know what are the most recurrent in a given text or group of text (pulled from a database) in ruby. Does anyone know what are the best practices? ...

size limit of a mysql query ruby/mysql

Hello everyone, I hope this is the appropriate place to ask my question. My mysql query currently looks like this @records = Record.find(:all, :select => "`records`.id, records.level as level, (SELECT (count( b.id ) + 1) FROM records as a, records as b WHERE a.id = records.id and b.skill > a.skill and b.created_at ='#{vandaag}' ...

Obtain Date from an RSS Feed in Ruby

I'm following instructions on http://www.rubyrss.com/ to parse a feed from craigslist.org: http://seattle.craigslist.org/sof/index.rss Everything seems to run fine, but when I can't get any dates from the parsed object: irb(main):010:0> rss.date NoMethodError: undefined method `date' for #<RSS::RDF:0x2c412b8> from (irb):10 irb...

Automatic associations in ruby on rails fixtures

As described in this article, I am using automatic associations in fixtures. For example, if a region object has a country id, instead of doing "country_id": 1, I do "country": "USA". "USA" is a label in my countries.yml file, so fixtures knows how to take care of this. However, this only works when you do not specify an ID value for ...

how can I pass a value between controllers (new -> create) in RoR

This may seem basic but I can't figure it out. I have a "Write Review" link which looks as follows: <%= link_to 'Write', new_review_path(@new, :vendor_id => @vendor.id) %> This creates the URL: reviews/new?vendor_id=10 All I want is to create a new Review object based on three inputs: vendor_id (above) user_id (which is working c...

Ruby's yield feature in relation to computer science

I recently discovered Ruby's blocks and yielding features, and I was wondering: where does this fit in terms of computer science theory? Is it a functional programming technique, or something more specific? ...

Restful Rails "perspectives"?

Say I want to render a page that isn't necessarily tied to a model. Up until now I have been creating a controller titled, "Pages", and a route for each page: map.home :controller => "pages", :action => "home" This isn't restful and it is tedious. Surely there is a better way to handle "perspectives" such as this? Note: I avoid the t...

ActiveRecord does not work on App Engine - What's the alternative?

Early reports of JRuby on Google App Engine indicate that ActiveRecord does not work. It was my understanding that this was the only way to talk to the database in Rails. Is this not the case? And, if not, what is the alternative? Is there a more direct way in Rails of interfacing with Google's BigTable datastore? ...

Ruby on Rails and Security

Has anyone ran across any good Powerpoint presentations on how to securely develop a web application in Ruby? ...

How to configure Ruby on Rails with Oracle?

There's several pages on the net that discuss this, but most are out of date or inaccurate in some what. What's the scoop? ...

streaming html from webrick?

Has anyone tried streaming html/text/content from webrick? I've tried assigning an IO to the response body, but webrick is waiting for the stream to be closed first. ...

Automatically Logging Exceptions in Ruby

Is there a library or easy way to catch exceptions thrown in a Ruby program and log it to a file? I've looked over log4r and logger, but the docs on both don't provide any examples on how I would do this. I run this program remotely and lose handles to stdout and stderr, if that information helps at all. What would you recommend? ...

Making RDoc Ruby Gem Default on Mac OS X

Hey all, I've recently installed RDoc version (2.4.3) through Ruby gems to replace the one shipped with Mac OS X (version 1.0.1). Unfortunately, I can still only use RDoc 1.0.1 when I call run "rdoc" at the command line. rdoc -v returns: RDoc V1.0.1 - 20041108 I tried amending the $PATH variable to point the first entry to the RDoc 2....

optpase returns true class while string is provided in cmd line arguments

I'm stuck in a totally stupid situation. When I use the snippet below, despite my command line being "./the_script.rb -s serv" and I check the value of the service variable within the code, it's always taken to be of boolean class by optparse. So I cannot get my string from the command line... any ideas ? opt = OptionParser.new do |op...

Ruby on Rails - how to display a date in format i need? Converting from YYYY-MM-DD HH:MM:SS UTC to MM/DD/YYYY

I am a RoR newbie. I tried a lot of things, finally came to following: <td> <%= Date.strptime(request.baseline_start_date, "%Y-%M-%D %H:%M:%S %Z").strftime("%M/%D/%Y")%> </td> But this is also giving me an error: $_ value need to be String (nil given) But I know that request.baseline_start_date gives me value (tried printing it se...