ruby

Redirect the "puts" command output to a log file

Hi, I am working on creating a daemon in Ruby using the daemons gem. I want to add output from the daemon into a log file. So I am wondering what is the easiest way to redirect puts from the console to a log file? ...

Correct Rails 2.1 way of doing things

Some of the answers to a question I had about redirect_to made me think about some other questions. Basically I'm writing a blog application using Rails 2.1. I've been trying to do most of it myself (as I know a bit of rails), but with reference to tutorials and references on the internet when I need it. I managed to get a simple blog ...

How to embed Ruby in an XNA engine?

I'm wondering if it's possible to embed Ruby as a scripting language in Microsoft XNA, and what's the best way to do that. I'm looking for something like Xnua, except for Ruby. I've stumbled upon Ruby.NET and IronRuby and both seem to be in very early stages, so I'm not sure how usable they are. Furthermore, I'm not sure if they'd work...

Ruby Daemons will not start

I am using the ruby daemons gem to create a custom daemon for my rails project. The only problem is that when I try to start the daemons ruby lib/daemons/test_ctl start that it fails and will not start. The log file has this output. # Logfile created on Wed Oct 22 16:14:23 +0000 2008 by / *** below you find the most recent exception th...

FizzBuzz using Ternary Operator

I've been reading up on conditional style expressions in ruby, however I came across one I couldn't quite understand to define the classic FizzBuzz problem. I understand the FizzBuzz problem and even wrote my own before finding the following quick solution utilising the ternary operator. If someone can explain to me how this chain works ...

How do I replace accented Latin characters in Ruby?

I have an ActiveRecord model, Foo, which has a name field. I'd like users to be able to search by name, but I'd like the search to ignore case and any accents. Thus, I'm also storing a canonical_name field against which to search: class Foo validates_presence_of :name before_validate :set_canonical_name private def set_cano...

Anyone using RailRoad diagrams generator?

I recently installed RailRoad gem to generate an .svg diagram of my app's models and controllers. The rake task keeps breaking with a similar error: 1.8/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:263:in `load_missing_constant': uninitialized constant I tried the rake task on 2 seperate apps and ...

Reusing the partials multiple times on one page in Ruby on Rails

I have a partial that renders a select box using the following method: <%= collection_select 'type', 'id', @types, "id", "name", {:prompt => true}, {:onchange => remote_function( :loading => "Form.Element.disable('go_button')", :url => '/sfc/criteria/services', :with => "'ty...

Shoulda testing workflow from the trenches

Everyone is talking about TDD (BDD) in Rails (and not just Rails) development world today. It's easy to find plenty of good general information about it, there are quite a few tools you can use for this purpose and there are many (good) examples of how to use them. Now, I'm already on the train. I like the idea (never did TDD before) a...

What should I use for a Ruby development environment on Windows?

Hi, I am playing around with Ruby in Windows using Notepad++ and the console but am finding this extremely inconvenient due to the lack of tabbed consoles. Any recommendations for a more comfortable environment? ...

Rails Cookie Setting Problems

I have a Rails app that sets a cookie and does a redirect to another server once the user is logged in. However, the cookie that the Rails app sets isn't seen by the server for some reason. I've tried setting http_only to false but I still can't even see the cookie unless the domain is the same as my Rails app. Here's the code I'm using ...

How do I view the HTTP response to an ActiveResource request?

I am trying to debug an ActiveResource call that is not working. What's the best way to view the HTTP response to the request ActiveResource is making? ...

How do I log the entire trace back of a Ruby exception using the default Rails logger?

I am working on rails project and I am trying to get exceptions to be logged to the rails log files. I know I can call logger.error $! to get the first line of the exception logged to the file. But, I want to get the entire trace stack logged as well. How do I log the entire trace back of an exception using the default rails logger? ...

How do you list the currently available objects in the current scope in ruby?

I'm new to ruby and I'm playing around with the irb. I found that I can list methods of an object using the ".methods" method, and that self.methods sort of gives me what I want (similar to python's dir(builtins)?), but how can I find the methods of a library/module I've loaded via include and require? irb(main):036:0* self.methods =>...

Problem requiring gem for acts_as_taggable in rails

I'm trying to get tags working in my rails application and want to use acts_as_taggable. Firstly I followed the instructions I found in Rails Recipies (a free sample bit online) that used the acts_as_taggable plugin. However, I then found this site which seems to have a gem for acts_as_taggable which is more advanced (has options for rel...

Interpret \n within irb or script/console

When using something like object.methods.sort.to_yaml I'd like to have irb interpret the \n characters rather than print them. I currently get the following output: --- \n- "&"\n- "*"\n- +\n- "-"\n- "<<"\n- <=>\n ... What I'd like is something similar to this: --- - "&" - "*" - + - "-" - "<<" - <=> Is this possible? Is the...

Why do I need to work harder to make my Rails application fit into a RESTful architecture?

The Background I started a Rails project recently and decided to use RESTful controllers. I created controllers for my key entities (such as Country) and added index, new, edit, create, show, update, delete. I added my map.resources :country to my routes file and life was good. After development progressed a little, I started to encoun...

Mongrel::DirHandler equivalent for Passenger

I'm using Mongrel::DirHandler to control response headers for static files - this works great on my dev machine. My production machine uses Passenger so my headers aren't getting set. How do I control headers for static files when using Passenger? snippet from my environment.rb: if defined? Mongrel::DirHandler module Mongrel clas...

Can I have url_for use a prefix option in Ruby on Rails?

In a project I am working on, Apache is set up to only forward requests that come in as /prefix/* to mongrel. How can I tell ruby on rails to generate all URLs with that prefix? I have the routes set up for forward to the correct controller action by doing this: map.connect 'sfc/:controller/:action' but that doesn't seem to affect t...

"gem install" freezes at "updating Gem source index for [..]"

For some weeks now I simply can't run gem install in windows. It sticks on this line: C:\Windows\System32>gem install rails --version 2.1.2 Bulk updating Gem source index for: http://gems.rubyforge.org/ Any ideas what it could be? ...