ruby

Rails has_many :through Find by Extra Attributes in Join Model

New to both Ruby and Rails but I'm book educated by now (which apparently means nothing, haha). I've got two models, Event and User joined through a table EventUser class User < ActiveRecord::Base has_many :event_users has_many :events, :through => :event_users end class EventUser < ActiveRecord::Base belongs_to :event belongs...

How do you monitor your Ruby programming productivity?

Ruby coders: How do you monitor your productivity? I'm curious to know what you use to keep track of how much you do and how well you do it. ...

Google Sketchup API - to a Windows App?

How can one interface with Google Sketchup, via the API, from a Windows App? I was looking at something written in C#/VB.NET but its seems like the only available Google Sketchup API is for Ruby. Any ideas on how to use that Ruby API from .NET? Is Ruby only serverside or can it be processed locally, offline? ...

Which license can I release stand-alone (exe, dmg) shoes-applications under?

If I create an application, using Shoes, would I have to license it under a open source license, or can I use it for closed-source/propietary stuff? The framework consists of a lot of moving parts, so it's not entirely clear to me. EDIT: The reason why I'm asking, is because of the notes at this page: Since both anal_pe and XPwn are...

Interested in Collective Programming for the web -- Ruby or Python or PHP?

For something like a personal recommendation system, machine learning type of stuff on a website, what language would be best? ...

How do I reload a running Shoes app after making source code changes?

I'd like to start tinkering around with Shoes. There is one thing I can't figure out. How do I reload a running Shoes application after saving changes to the source code? I've already found the hotkeys for opening the Help, Console, and a new app. To me it seems odd that the developer would be forced to close and restart a Shoes app ea...

How does ruby serialization (Marshaling) work?

I have found some info on the subject (like this link), but nothing that tells me how it actually works under the covers. If you don't want to read the essay below, here are the real questions: How should I implement the marshal_dump and marshal_load methods? even a simple example will do. when marshal_load is called, how does it 'kn...

Why is ActiveRecord issuing a separate query per join?

I'm doing an ActiveRecord find operation (via the "will_paginate" library) like this: contacts = Contact.paginate(:all, :conditions => conditions_specified, :select => "DISTINCT contacts.*", :joins => joins, :include => [:addresses, :emails, :phone_numbers, {:addresses => :organization}], :page => page, :per_pa...

Ruby Basics

What is the best online resource for learning the ruby language? Preferably intermediate and advanced topics. ...

Convert an array into an index hash in Ruby

Let's say I have an array, and I want to make a hash so I can quickly ask "is X in the array?". In perl, there is an easy (and fast) way to do this: my @array = qw( 1 2 3 ); my %hash; @hash{@array} = undef; This generates a hash that looks like: { 1 => undef, 2 => undef, 3 => undef, } The best I've come up with in Ruby ...

Using named_scope to get row count

Rails gurus: I've just discovered named_scope thanks to another SO user. :) I'd like to get the count of a set of rows - i.e. a SELECT COUNT(*). Additionally, I want to still be able to chain named scopes in the call. Is this a legitimate (albeit weird) usage of named scope? named_scope :count, :select => "COUNT(*) as count_all" So...

How do I pass/get command line parameters?

Hello, I am trying to use Shoes and I need to pass it command-line parameters (basically, my Shoes app will be called from another pre-existing app and this would allow me to pre-fill some parts of shoes). Should I then call it using bin/shoes wrapper? It seems I can not pass arguments to shoes wrapper (it concatenates all parameters a...

Tab movement in shoes

Hello, I have a problem I have a: stack { flow { para "Enter text:" edit_line } edit_box } (simplified version). When user is on edit_line and presses tab, I want it to move to edit_box control (currently, it just loses focus). Thanks, Juraj. ...

RubyOnRails 2.2 + Jquery UI Sortable & AJAX: This is how I did it. Is there a better way?

Hello, In a Rails 2.2 project, I'm having users put together a list of projects into a portfolio object (i.e.: PortfolioHasManyProjects). On the page is a Rails form for regular text, titles etc., as well as 2 sortable lists; the lists are used for dragging projects from the global-project-list into your portfolio-project-list. It is s...

Problem with procs created within loops accessing loop variables

I am a ruby newb and am having a problem with procs created inside loops accessing loop variables. Here is a code file demonstrating the problem. class Route def initialize options = {} options.each do |k,v| self.instance_variable_set("@#{k}", v) self.class.send(:define_method, k, proc{self.instance_variable_get("@#...

Ruby: How to find item in array which has the most occurrences?

[1, 1, 1, 2, 3] => 1 ['cat', 'dog', 'snake', 'dog'] => dog ...

Starting Ruby

Recognizing this as a similar question... So this link shows how to install Ruby on Rails on Mac, and then using it w/ XCode. (1) Is there an interpreter like Python's IDLE for Ruby? If so, where to get it. (2) How do I run Ruby w/o using an interpreter? (3) How do I get started using Ruby for web apps - does this require me to learn...

Programming Language Choice - Longevity and Community

I work for a start up that is currently researching what programming language they will adopt. The following criteria have been identified by management. The language will be used to develop web based applications. Having a system that allows for easy generation of business reports would be a bonus (iReport, Crystal Reports) Longevity...

Cleanest way to create a Hash from an Array

I seem to run into this very often. I need to build a Hash from an array using an attribute of each object in the array as the key. Lets say I need a hash of example uses ActiveRecord objecs keyed by their ids Common way: ary = [collection of ActiveRecord objects] hash = ary.inject({}) {|hash, obj| hash[obj.id] = obj } Another Way: ...

database configuration does not specify adapter

Hi all, I'm getting this error when I'm trying to connect to a mysql database. The problem is that the application works for weeks, and then randomly I get this message. When I get this error message the application is not able to reconnect to the database until I restart it. I'm using a configuration file to connect to the database, a...