ruby

will_paginate route only works on page > 1

I have the following routes defined: map.resources :categories, :has_many => :downloads map.resources :downloads, :member => {:go => :get}, :collection => {:tag => :get} map.connect '/downlods/page/:page', :controller => 'downloads', :action => 'index' map.connect '/categories/:category_id/downloads/page/:page', :controller => 'download...

IRb: how to start an interactive ruby session with pre-loaded classes

Hi, As I am going through my journey by adopting the Ruby language, I spend a lot of time inside IRb. It's just fantastic! But, as I am not very aware of it's capabilities, and still a nuby with Ruby, I would like to know the following: How can I 'flush' the session, without restarting IRb (or is this not possible). How can I configur...

Twitter + Grackle, determining the logged in user

This is crazy, but I'm stumped! Once my user has logged into twitter via OAuth how do I determine their username using grackle? @twitter = Grackle::Client.new(:auth => { :type => :oauth, :consumer_key => consumer_key, :consumer_secret => consumer_secret, :token => @access_token.token, :token_secret => @access_token.secret }) ...

using sql loader in ruby

Hi, I just wonder if you know where to find a tutorial or samples of a Ruby script using sql *loader? ...

Build a ruby daemon that integrates my rails environement

Hi guys, I need to build a ruby daemon that will use the freeswitcher eventmachine library for freeswitch. Since few days I as looking the web for the best solution to build a ruby daemon that will integrate my rails environment, specailly my active record models. I've take a look to the excellent Ryan Bates screencast (episodes 129 cu...

Headers set on embedding

Lets say I have a URL (http://www.example.com/something). Is the following scenario somehow possible? A) The user visits the URL directly and a standard page with markup, js, etc. is shown. B) The user embeds the same URL in an image tag and the URL is served only as an image. ...

Restrictons of Python compared to Ruby: lambda's

Hi, I was going over some pages from WikiVS, that I quote from: because lambdas in Python are restricted to expressions and cannot contain statements I would like to know what would be a good example (or more) where this restriction would be, preferably compared to the Ruby language. Thank you for your answers, comments and fe...

Rails NoMethodError in loop when method exists

Good day all. I'm running into a bit of a problem getting a script running on my production environment, even though it works just fine on my dev box. I've verified that all the requisite gems and such are the same version. I should mention that the script is intended to be run with the script/runner command. Here is a super-condense...

ActiveRecord finding from inside a serialized field

While working with ActiveRecord I have a table which stores a serialized array of participant usernames for each row in one field. Is there an easy way to search for all rows who contain a specific user? class Thing < ActiveRecord::Base serialize :participants end I realise I could just make a new linked table for the participants, ...

What's the equivalent of Ruby's class @@variable in Python?

In Ruby 1.9, I can use its class variable like the following: class Sample @@count = 0 def initialize @@count += 1 end def count @@count end end sample = Sample.new puts sample.count # Output: 1 sample2 = Sample.new puts sample2.count # Output: 2 How can I achieve the above in Python 2.5+ ? ...

How to use ImageMagick to batch desaturate images?

I have an image that is black text with some gray and pale yellowish background. I basically want to keep the text as black as possible, and make the gray and yellow comparatively lighter...at the very least, turn yellow into a light gray. What's the most efficient way to do that in ImageMagick? ...

Generating a static website from a set of content data (possibly with webgen, webby or a similar toolkit)

My company (an engineering firm) is looking to redesign their website with some dynamic content. We have a nice portfolio of projects that we'd like to present on our site by category. To elaborate, I'd like to have a "Projects Category" menu, where you can choose a sub-project category (such as churches, schools, etc) which links to a...

Ruby: How do I define a datetime field in YAML?

I'm creating test data for a Rails app. How do I define the value for a datetime field in YAML? ...

What's the best way to mix Ruby and other languages? (Especially C++)

Hi, I'm learning Ruby, and I'm starting to play with building extensions in C. I have Programming Ruby The Pragmatic Programmers' Guide and so I can follow that for the basic nuts and bolts. What I was wondering is if there already existed some nifty frameworks/whatever to help interoperability between Ruby and other languages, with C++...

select for update with ruby oci8

how do I do a 'select for update' and then 'update' the row using ruby oci8. I have two fields counter1 and counter2 in a table which has only 1 record. I want to select the values from this table and then increment them by locking the row using select for update. thanks. ...

Paperclip Refreshing of Thumbnails not working with S3

I have Paperclip installed as a gem and i am trying to refresh the thumbnail size of the images. I'm running this command: rake paperclip:refresh:thumbnails CLASS=User and receiving this error: ...rake aborted! The specified key does not exist. Any ideas? Finn ...

Make emacs autocomplete Ruby methods

Is there a way to make emacs pull autocompletions of ruby methods the way Eclipse and NetBeans do? That is if I type File. and press CTRL-space in Eclipse I will get a list of File methods. Same with variables. I have installed autocomplete plugin, ruby-mode, rinari and cedet, but so far it will complete local variable and method names, ...

validating creation by post_id and ip_address - Ruby on Rails

I have created a blog application using Ruby on Rails which includes the ability to vote on posts. A user can click vote and a record is created in the vote table. I am now trying to limit that same person from voting for a post multiple times. class Post has_many :votes end class Vote belongs_to :post end When a vote record is c...

Alternative to rescue in Ruby?

It seems like I have begin ... rescue ... end statements everywhere in my code! This doesn't seem like the correct thing to do. Can anyone suggest how I can catch any exceptions without having to place everything inside begin ... rescue ... end? Any way to just tell Ruby to shut up and just keep going even if an exception is raised? ...

Ruby - Get request body from incoming http call

Hi, I am receiving http requests to my rails application to a url /account/postback The body of this incoming request contains some json that I need to retrieve, how can I do this in ruby? Thanks, Andy ...