ruby

How can I create a loop in an onClick event?

I want to write an onClick event which submits a form several times, iterating through selected items in a multi-select field, submitting once for each. How do I code the loop? I'm working in Ruby on Rails and using remote_function() to generate the javascript for the ajax call. ...

Is there a good admin generator for Ruby on Rails?

My current project is in Rails. Coming from a Symfony (PHP) and Django (Python) background, they both have excellent admin generators. Seems like this is missing in Rails. For those who aren't familiar with Symfony or Django, they both allow you to specify some metadata around your models to automatically (dynamically) generate an adm...

Recovering from a broken TCP socket in Ruby when in gets()

I'm reading lines of input on a TCP socket, similar to this: class Bla def getcmd @sock.gets unless @sock.closed? end def start srv = TCPServer.new(5000) @sock = srv.accept while ! @sock.closed? ans = getcmd end end end If the endpoint terminates the connection while getline() is running then ...

Best Practice for Model Design in Ruby on Rails

The RoR tutorials posit one model per table for the ORM to work. My DB schema has some 70 tables divided conceptually into 5 groups of functionality (eg, any given table lives in one and only one functional group, and relations between tables of different groups are minimised.) So: should I design a model per conceptual group, or should...

How do I get logout to work on RubyCAS-Server?

I have installed and setup RubyCAS-Server and RubyCAS-Client on my machine. Login works perfectly but when I try to logout I get this error message from the RubyCAS-Server: Camping Problem! CASServer::Controllers::Logout.GET ActiveRecord::StatementInvalid Mysql::Error: Unknown column 'username' in 'where clause': SELECT * FROM `casser...

What is best way to debug Shoes applications?

Shoes has some built in dump commands (Shoes.debug), but are there other tools that can debug the code without injecting debug messages throughout? Something like gdb would be great. ...

Importing XML file in Rails app, UTF-16 encoding problem

I'm trying to import an XML file via a web page in a Ruby on Rails application, the code ruby view code is as follows (I've removed HTML layout tags to make reading the code easier) <% form_for( :fmfile, :url => '/fmfiles', :html => { :method => :post, :name => 'Form_Import_DDR', :enctype => 'multipart/form-data' } ) do |f| %> <%= f.fil...

Hidden features of Ruby

Continuing the "Hidden features of ..." meme, let's share the lesser-known but useful features of Ruby programming language. Try to limit this discussion with core Ruby, without any Ruby on Rails stuff. See also: Hidden features of C# Hidden features of Java Hidden features of JavaScript Hidden features of Ruby on Rails Hidden featur...

Should rails models be concerned with other models for the sake of skinny controllers?

I read everywhere that business logic belongs in the models and not in controller but where is the limit? I am toying with a personnal accounting application. Account Entry Operation When creating an operation it is only valid if the corresponding entries are created and linked to accounts so that the operation is balanced for exempl...

Convert a .doc or .pdf to an image and display a thumbnail in Ruby?

Does anyone know how to generate document thumbnails in Ruby (or C, python...) ...

Why is RSpec so slow under Rails?

Whenever I run rspec tests for my Rails application it takes forever and a day of overhead before it actually starts running tests. Why is rspec so slow? Is there a way to speed up Rails' initial load or single out the part of my Rails app I need (e.g. ActiveRecord stuff only) so it doesn't load absolutely everything to run a few tests...

What's the best way to hash a url in ruby?

I'm writing a web app that points to external links. I'm looking to create a non-sequential, non-guessable id for each document that I can use in the URL. I did the obvious thing: treating the url as a string and str#crypt on it, but that seems to choke on any non-alphanumberic characters, like the slashes, dots and underscores. Any sug...

How to write a Rails mixin that spans across model, controller, and view.

In an effort to reduce code duplication in my little Rails app, I've been working on getting common code between my models into it's own separate module, so far so good. The model stuff is fairly easy, I just have to include the module at the beginning, e.g.: class Iso < Sale include Shared::TracksSerialNumberExtension include Shar...

Learning New Language between Ruby & F#

After finish reading "The Pragmatic Programmer", I have come to a conclusion that it's time for me to learn some new language other than C#/VB.NET every year. I have come down to 2 languages that I would like to go with. Ruby & F# Should I go with Ruby or F#? That is the question. Ruby is dynamic language, where a lot of C# features ...

Going Ruby: Straight to IronRuby?

Hey guys, I just started to learn Ruby and as a .Net developer, I'm wondering if I should just go straight ahead and use IronRuby, without trying some pure Ruby first. What do you think? Will I be missing anything? -- rauchy ...

Ruby exception inheritance with dynamically generated classes

I'm new to Ruby, so I'm having some trouble understanding this weird exception problem I'm having. I'm using the ruby-aaws gem to access Amazon ECS: http://www.caliban.org/ruby/ruby-aws/. This defines a class Amazon::AWS:Error: module Amazon module AWS # All dynamically generated exceptions occur within this namespace. # m...

How do I programmatically convert mp3 to an itunes-playable aac/m4a file?

I've been looking for a way to convert an mp3 to aac programmatically or via the command line with no luck. Ideally, I'd have a snippet of code that I could call from my rails app that converts an mp3 to an aac. I installed ffmpeg and libfaac and was able to create an aac file with the following command: ffmpeg -i test.mp3 -acodec lib...

How should Rails models containing database and non-database datasources be broken up?

So I'm working on a Rails app to get the feeling for the whole thing. I've got a Product model that's a standard ActiveRecord model. However, I also want to get some additional product info from Amazon ECS. So my complete model gets some of its info from the database and some from the web service. My question is, should I: Make two mod...

Which ruby interpreter are you looking forward to?

There are multiple Ruby implementations in the works right now. Which are you looking forward to and why? Do you actively use a non-MRI implementation in production? Some of the options include: Ruby MRI (original 1.8 branch) YARV (official 1.9) JRuby Rubinius IronRuby MagLev (Thanks Julian) ...

How do I quickly do something in Rmagick to test it work

I need to be able to quickly convert an image (inside a rails controller) so that the hosting company using managing our application can quickly test at any time to ensure that rmagick is not only successfully installed, but can be called throgh the rails stiack, what is the quickest clean code I can use to do this? ...