ruby

Is there any Ruby framework to return database data to XML?

Instead of writing the SQL query, is there any lazy way to get the data from database in XML format. ...

How can I make sure the Sphinx daemon runs?

I'm working on setting up a production server using CentOS 5.3, Apache, and Phusion Passenger (mod_rails). I have an app that uses the Sphinx search engine and the Thinking Sphinx gem. According to the Thinking Sphinx docs... If you actually want to search against the indexed data, then you’ll need Sphinx’s searchd daemon to be ...

Regex use in reading file .txt and returning information to screen

So I'm trying to figure out how to take entries from the user in this case "CLOWN" and "112". I then take those values and pass them to my regex expression in the File.foreach code. Its opening a enrollment.txt file. The code is then supposed to get all the lines of the .txt and print it to screen based on the two entered values #WARNIN...

validates_presence_of causes after_initialize to be called with a weird self

I've had this model which was working fine: class Weight < ActiveRecord::Base belongs_to :user validates_presence_of :weight, :measured_on attr_accessible :weight, :measured_on def after_initialize self.measured_on ||= Date.today end end I added it this line validates_uniqueness_of :measured_on, :scope => :user_id an...

Why does Rake crash my Mac OSX ?

Hi ! I'm running Mac OSX 10.6.2 and I've got a strange problem with rake and my ruby applications. Has soon as I launch a rake command my mac crashes and ask me to reboot (dark screen). This occure when I try to run a Rakefile or even simply if I type: rake --version I tried reinstalling rake by running the install.rb file of the lat...

Idiomatic object creation in ruby

In ruby, I often find myself writing the following: class Foo def initialize(bar, baz) @bar = bar @baz = baz end << more stuff >> end or even class Foo attr_accessor :bar, :baz def initialize(bar, baz) @bar = bar @baz = baz end << more stuff >> end I'm always keen to minimise boilerplate as much a...

Gem install errors writable and PATH

These are the two errors I am getting. I am on OS X. Honestly, don't know if I installed via gem or not - if that matters. WARNING: Installing to ~/.gem since /Library/Ruby/Gems/1.8 and /usr/bin aren't both writable. WARNING: You don't have /Users/M/.gem/ruby/1.8/bin in your PATH, gem executables will not run. ...

Generate new models and schema at runtime

Let's say your app enables users to create their own tables in the database to hold their own, custom data. Each table would have it's own schema. What are some good approaches? My first stab involved dynamically creating migration files and model files bu I'd like to run this on heroku where you can't write to the filesystem. I'm thi...

SHA-1 hash for storing Files

After reading this, it sounds like a great idea to store files using the SHA-1 for the directory. I have no idea what this means however, all I know is that SHA-1 and MD5 are hashing algorithms. If I calculate the SHA-1 hash using this ruby script, and I change the file's content (which changes the hash), how do I know where the file i...

Using Ruby's "ready?" IO method with gets, puts, etc

The standard Ruby library "io/wait" provides a method on IO objects ready? that returns non-nil if there is input available, nil or false otherwise. I know some methods like sysread and syswrite are not safe to use with higher level methods such as gets and read, and wanted to know if ready? was safe to mix with the higher level methods...

uninitialized constant

Hi. I'm trying to do this tutorial-> http://netbeans.org/kb/docs/ruby/rapid-ruby-weblog.html BUT its giving me this error: NameError in PostsController#index uninitialized constant PostsController::Posts I don't know whats wrong ...

gobject.timeout_add example

I need to perform some actions periodically on my GTK Ruby program and i am looking for the working example of using gobject.timeout_add() function. ...

Adding standalone Ruby Files to a Ruby on Rails project

Hi, I have a ruby on rails project with scaffolding , views, layouts, models and such. I also have some standalone ruby (.rb) files which i would like to include in my afforementioned project. Is it possible to simply call these methods defined in these rb files by placing them somewhere and calling them from the controller or so? If ...

Is ri worth showing new users? (Ruby)

I've been working on a Ruby learning guide and I was told I should write about RI (Ruby Interactive Reference). After looking around the web I decided there wasn't that much information about the tool. Is that a problem? RI seems like a terribly ineffective tool, and poorly designed! Manpages have always been a ghastly sight to read whi...

Ruby video and audio processing

Is there a Ruby library for recording and streaming videos + audio from a webcam? ...

How can this 6 line method be refactored to be more readable?

Hi everyone, I'm trying to clean up this ridonkulously ugly method here, that's crying out for refactoring, but I'm not sure what kind of structure would do this best (i.e. a case statement, or simply a carefully formatted if then statements) At first glance, it looks like it would be an ideal place for a case statement with a few well...

Distribute range in array

I need to create one array of numbers inside one range, like: [1..5] in 10 times = [1,1,2,2,3,3,4,4,5,5] [1..5] in 5 times = [1,2,3,4,5] [1..5] in 3 times = [1,3,5] def distribute(start_value, end_value, times, is_integer) array = Array.new(times-1) min_value = [end_value,start_value].min max_value = [end_value,start_...

Heroku, Problem/Question...

I was referred to Heroku for Ruby on Rails hosting and so far I think I am really going to like it. Just wondering if I anyone out there can help me figure out what is wrong. I follow there instructions for creating an app on there site, create and commit git, push the code and it shows up at http://mylifebattlecry.heroku.com (though t...

Convert XML collection (of Pivotal Tracker stories) to Ruby hash/object

I have a collection of stories in an XML format. I would like to parse the file and return each story as either hash or Ruby object, so that I can further manipulate the data within a Ruby script. Does Nokogiri support this, or is there a better tool/library to use? The XML document has the following structure, returned via Pivotal Tra...

How do I create a link to a specific Post object in a Rails view?

I am new to rails so excuse any easy questions. I have developed a blog and I am doing some customization. Just curious, if I want to render a specific post on my index.html.erb page is that possible. For instance if I create a post, title: Cool Post and it has a post_id of 25 in the table, in my index page can I call that specific post ...