ruby

How do you track page views on a view

Is there a plugin for this or a gem that I can use. I was thinking about just writing it to a table when a view was called in the controller. Is this the best way? I see stackoverflow has this functionality how do they do it? ...

How to get Phusion Passenger, MySQL and Rails to play nicely in production

I've written a rails app that's been running fine for a while without a database. Now, I'm dropping the registration database into the mix. It's not working in production. Everything works fine, of course, on my Mac. Here's the production environment: - Ubuntu Hardy - Phusion Passenger - Rails 2.3.2 MySQL on the machine is running fin...

Testing for undefined variables in Ruby a la JavaScript?

Hi, In JavaScript there's a useful way to test for a variable which has never been defined at any given point. For example, the following snippet of code will return true if the variable bob has not been defined: typeof(bob)=='undefined' How do I accomplish the same test in Ruby? edit: I'm looking for a test which is equally compact...

Creating a record for an association unobtrusively when attempting access?

I have a simple has_one/belongs_to relationship between two models. This is a new association in my application so there are many records that do not yet have the associated record created. Throughout my application I'm assuming the model has the association and I'm accessing its attributes and methods. However, because the associatio...

Have you ever used a "class instance variable" in any of your Ruby code?

I can understand why you would need a class variable to keep track of things like the total number of objects that have been instantiated in that class. And I can understand why you would need an instance variable to store attributes of a particular object in that class. But class instance variables I just can't seem to justify. As I ...

How to update to Ruby 1.8.7

I am new to Ruby, so bear with me. I've been trying to update my Ruby to 1.8.7 and just ran into many issues on my Mac OS X (10.5.7). So really, how do you update to Ruby 1.8.7? Thanks. ...

Clearer way to parse a token out of a string in ruby

I'm trying to clean up something for the hell of it, and looking for some better ways of going about it. The idea is that instead of using regular expressions in my rules for parsing a string, I'd like to use something closer to the routes syntax "something/:searchitem/somethingelse", then given a string like "/something/FOUNDIT/somethin...

Ruby: Detect number of CPUs installed

I already found a solution for "Most unixes" via cmdline "cat /proc/cpuinfo", but a pure-ruby solution would be nicer... ...

Grab mouse movement

I am writing a little utill for me on ruby using qt. How to access global mouse movement and keyboard input events? ...

Extract and multiple integers from user-input string in Ruby?

I want to take multiple integer inputs in same line eg :- input -1 -1 500 500 so that I can multiply them. I am taking the input in a string from keyboard - then what should I do? ...

DB connection problem in production

I have a separate DB for one model in my application and in development mode the connection is working properly, in production however it isn't. production: adapter: mysql host: myhost username: root password: database: production_db users_production: adapter: mysql host: myhost username: root password: database: ot...

Overwriting/Adding an ActiveRecord association dynamically using a singleton class

The business logic is this: Users are in a Boat through a join table, I guess let's call that model a Ticket. But when a User instance wants to check who else is on the boat, there's a condition that asks if that user has permission see everyone on the Boat, or just certain people on the Boat. If a User can see everyone, the normal dea...

What are your favourite Rubygems?

Possible Duplicate: What are the "Must Have" Ruby Gems There are a load of great Rubygems out there that do some amazing things. In fact, I sometimes wonder what I'd do without Rubygems - they certainly give a load of appeal to Ruby and Rails. What are you favorites, and what would you recommend to install? ...

Destroy cookies in rails, facebook connect, facebooker plugin

So I have sort of a weird situation going on. I am using the Facebooker plugin for rails where I want users to be able to login and logout with their facebook profiles. However, once users logout, if I refresh the page, it logs them back in. This is only when users log in with facebook connect. I think the problem is that a rogue coo...

Ruby Array

EDIT : First part removed i found the answer. I have the following problem : im reading a number from the input and trying to use that number to access a given array position. I get the following results value #=> "0" value.to_i #=> 0 myArray[0] #=> MyObject myArray[value.to_i] #=> nil ...

Has Python changed to more object oriented?

I remember that at one point, it was said that Python is less object oriented than Ruby, since in Ruby, everything is an object. Has this changed for Python as well? Is the latest Python more object oriented than the previous version? ...

How does Ruby and PHP differ in their evaluation engines?

I once found an article with the differences between how PHP and Ruby handle different types of variables matched with certain testing conditions (ie: isempty, isset, etc). How do they differ? ...

How can Ruby's attr_accessor produce class variables or class instance variables instead of instance variables?

If I have a class with an attr_accessor, it defaults to creating an instance variable along with the corresponding getters and setters. But instead of creating an instance variable, is there a way to get it to create a class variable or a class instance variable instead? ...

Why can't Rails work with mod_ruby?

I'm sorry if this sounds like a stupid question, because it seems to be one of those "no duh" things, but can someone explain to me why Rails needs its own server (Mongrel, WEBrick, mod_rails, etc) and can't simply use mod_ruby? ...

What is a good method to bypass authentication and/or authorization in development mode?

I have several actions that are protected by filters that check for logged_in? and admin? and spit out 401 or 403 errors respectively if the tests fail. What's a good way of getting around these filters in development mode only so I can test out my app? I can't go through the actual login procedure because it relies on infrastructure I...