ruby

Comparing two lambdas/Procs in Ruby

This has been driving me nuts, I'm posting here after a lot of looking around. I'd like to know if two variables pointing to the same Proc are the pointing to the same Proc. I'm sure it must be something I'm not getting so for example why do all of these return false? class LambdaFunctions def self.LambdaFunction1 lambda { |t| t...

Capistrano asks for password when deploying, despite SSH keys

My ssh keys are definitely set up correctly, as I'm never prompted for the password when using ssh. But capistrano still asks for a password when deploying with cap deploy. It doesn't ask for the password when I setup with cap deploy:setup though, strangely enough. It would make the deployment cycle so much smoother without a password pr...

Is checking whether a DataMapper (or other ORM) model is persisted a code smell?

I've found myself starting to leverage checking persistence to get my models to 'work'. It seems convenient and correct to include a persistence check. On the other hand, it feels a little shady, as if I was being overly cautious or breaking the ORM abstraction in a small way. An example might be: class Shipment include DataMapper:Re...

git-commit-notifier with gmail

First of all you have to know I'm total Ruby noob :) I installed git-commit-notifier (http://github.com/ilozka/git-commit-notifier) on my system (Ubuntu 10.04) and followed all the installation instructions but every time I push to my git repository I get this error message: remote: Sending mail... remote: /usr/lib/ruby/1.8/net/smtp.r...

RoR: Why is this if-statement failing?

Why is the second if statement failing in the following code block? The output from the console indicates that the private parameter is 0, so it should be passing? The private parameter is from a checkbox in the new form, that I'm using to set a boolean field in the model. if (((params[:note])[:text]) != "") logger.debug("passed first...

Is it a bug for method hash#to_json in Rails?

I use rails 2.3.8 def index @posts = Post.all respond_to do |format| format.html # index.html.erb format.json { render :json => ({ :results => @posts.size, :rows => @posts.to_json(:only => [:id, :title, :click_count, :body])}).to_json } end end the generated json data is: {"rows":"[{\"title\":\"ruby\",...

Why am I getting a "SystemStackError: stack level too deep" in my rails3 beta4 model

Hi there. I'm getting the following error: SystemStackError: stack level too deep when executing the following code in rails3 beta4 under ruby 1.9.2-rc1: ruby-1.9.2-rc1 > f = Forum.all.first => #<Forum id: 1, title: "Forum 1", description: "Description 1", content: "Content 1", parent_id: nil, user_id: 1, forum_type: "forum", create...

Is there any partial kind of thing for controllers in Ruby on Rails

I have a controller having more than 1000 lines of code. Right not I am doing Code review for this controller. I arrange my methods according to the module. Now I realise that my controller is not easy to maintain and so I want to something like following class UsersController < ApplicationController #Code to require files here ...

What hash function does Ruby use?

What is Ruby's hash function algorithm? ...

Compiled Application with Ruby config files (yml)

I compiled a program from source on mac os x which tells me to use the supplied example config files, but how can I run a specific config file? Readme shows what to edit in the config but not how to load it. More specifically this program (http://github.com/carsonmcdonald/HTTP-Live-Video-Stream-Segmenter-and-Distributor) ...

How to pass Array as parameter to SOAP in Ruby

Currently I'm using Savon to work with WebService in ruby. It works pretty well but I have difficulty to pass parameter for argument of SOAP array type. Following code doesn't work properly: ids = [0,1,2] client.do_get_items { |soap| soap.body = { 'item-list' => ids } I would appreciate if you can solve my problem or propose an al...

Ruby equivalent to func_get_args()

In many PHP-application, when things are badly documented or weird implemented, the function func_get_args() comes to resque. It allows me to inspect (or print) what variables are passed along to a function function poorly_documented($op, $a2, $a3 = 'default', $rest) { var_dump(func_get_args()); // ... } Allthough in Ruby I hardly...

ActiveRecord and has_many, :through link backs

Is there a simple way to specify a has_many :through relationship where you're linking the same data type? eg. One User has many friends (who are all users). I'd like to be able to store data about the friendship, so has_many :through seems to be the obvious choice, but then you'd have to define two :user_id columns, which of course does...

What's the best way to detect date formats in user submitted data?

I'm reading csv data uploaded by users in my Ruby on Rails app. When a user specifies that a particular column has dates(or times), I want to be able to automatically detect the format. This means it can be in American or British formats (any of dd/mm/yy, mm/dd/yy, yyyy-mm-dd, 12 Feb 2010, etc etc) I have tried parsedate in Ruby but i...

Sort Array in Controller

Hello I'd like to sort an array in a Rails Controller. I want to sort the array before I loop over it in the View @projects = Project.all.sort #throws error #and @projects = Project.all @projects.sort # throws error throws this error: undefined method <=> for #<Project:0x101f70b28> but when I query: @projects.respond_to...

Regex parse using Nokogiri

Using Nokogiri, I need to parse a block given: <div class="some_class"> 12 AB / 4+ CD <br/> 2,600 Dollars <br/> </div> So i need get AB, CD and Dollars values (if exist). ab = p.css(".some_class").text[....some regex....] cd = p.css(".some_class").text[....some regex....] dollars = p.css(".some_class").text[....some regex......

textarea character count in Rails

Hello, I want to use observe_field to give me the character count of the textarea, updated as you type. What am I doing wrong here? <div class="field"> <%= observe_field :micropost_content, :function => "$('micropost_content').value.length" %> <%= f.text_area :content %> </div> ...

How to change rubygems platform from x86-mingw32 to x86-mswin32-60 on windows

Hi I am doing some ruby scripting in windows, which involves opening and closing a browser. To that end I needed some special gems to interface to the native windows system calls. But when I tried > gem install sys-proctable , it yielded ERROR: Could not find a valid gem ´sys-proctable´ (>= 0), here is why: Found sys-proc...

Ruby: what's the difference with these two Arrays?

Getting confused by syntax here, but what is the difference between: foo[x][y] and foo[x, y] ...

Authlogic and OpenID registration and login in one action

I was playing with Rayan Bates http://railscasts.com/episodes/170-openid-with-authlogic sources as the basis. So I created few icons for OpenID providers, like Google, Yandex, OpenID, and user have to choose which one to use (similar like here on stackoverflow). So everything is fine. Now I decide to make only one click for login or reg...