ruby

User has_many :users, :through => :friends - how?

Hi! This is my code: class Friend < ActiveRecord::Base belongs_to :user belongs_to :friend, :class_name => "User", :foreign_key => "friend_id" end class User < ActiveRecord::Base #... has_many :friends has_many :users, :through => :friends #... end When I now start adding users by... user.users << user2 user.save Only...

Treetop basic parsing and regular expression usage

I'm developing a script using the ruby Treetop library and having issues working with its syntax for regex's. First off, many regular expressions that work in other settings dont work the same in treetop. This is my grammar: (myline.treetop) grammar MyLine rule line string whitespace condition end rule string ...

rfacebook and facebook image uploading api

I'm using rfacebook gem to interact with facebook connect. And I'm having a problem with uploading images. As facebook api says, the data should be transferred in a hash like json object. So I'm making an hash publish_values = { :uid => @post.profile.channel_uid, :message => @post.content, :auto_publish => ...

How to make Rails caches_page survive a capistrano deploy?

Is it possible to configure Rails so caches created with caches_page survive a Capistrano deploy? Ie, can I configure the cache to be saved into a shared directory rather than in the public directory? ...

How to convert image file to byte array using ruby

hi I need to pass image as byte array to .NET SOAP web service. Can anyone give me example how to convert uploaded image file to byte array using ruby? ...

Whats up with the £ symbol

I'm a bit confused with the '£' symbol in Ruby. In JRuby if I do : puts '£40' in a .rb file I run this, I get ¬£40 In JRuby IRB I get : >> pung = 'h40' => "h40" >> pung.gsub!('h', '£') pung.gsub!('h', '£') => "\24340" The pound symbol is output as \243. In pure Ruby IRB, I cant even enter the £ symbol.. The cursor jumps to the...

Simple Ruby Command Line Question

Um - I feel like an idiot, but.... ruby -e '3+5' Outputs nothing (Windows 7, Ruby 1.8.7, Cygwin or Git Bash). What am I missing? Extra credit - will this also allow the extra cool bundle (stolen from TextMate) Execute and Update # => markers to work properly? EDIT Ok that worked, and I'll accept the answer, but e-texteditor still do...

Deep relationships in Rails

I have some projects. Those projects have users through memberships. However, those users belong to companies. Question is, how do I find out which companies can access a project? Ideally I'd be able to do project.users.companies, but that won't work. Is there a nice, pleasant way of doing this? ...

How can I generate zip file without saving to the disk with Ruby?

I have generated many pdf files in memory and I want to compress them into one zip file before sending it as a email attachment. I have looked at Rubyzip and it does not allows me to create a zip file without saving it to disk (maybe I am wrong). Is there any way I can compress those file without creating a temp file ? ...

Conditions with whitespaces in activerecord find

So i am trying to do this Order.find :all, :conditions => "org = 'test org'" what ends up firing is SELECT * FROM `orders` WHERE (org = 'test org') the whitespace in the argument gets stripped. what am i missing.. im really stumped here. please help! ...

Rspec > testing database views

How can database views be tested in Rspec? Every scenario is wrapped in a transaction and the data does not look like it is being persisted to the database (MySQL in my case). My view returns with an empty result set because none of the records are being persisted in the transaction. I am validating that the records are not being stor...

RSpec: Stubbing out calls for certain parameters

I want to stub out a method only for a certain parameter. Say I have a class class Foo def bar(i) i*2 end end Now I want to stub out the method bar only for calls with a value of say 3 and return the method return value in all other cases: >> foo = Foo.new >> foo.bar(2) => 4 >> foo.stub!(:bar).with(3).and_return(:borked) >> f...

ruby parallel assignment, step question

so, i'm trying to learn ruby by doing some project euler questions, and i've run into a couple things i can't explain, and the comma ?operator? is in the middle of both. i haven't been able to find good documentation for this, maybe i'm just not using the google as I should, but good ruby documentation seems a little sparse . . . 1: how...

'memcache-client' problem - app can't load the gem

Hi all - i'm trying to get memcached and the Interlock plugin working with a new rails app. The weird thing is that they both work fine in another app on the same machine and i can't figure out the difference that's stopping this app. The new app is rails 2.3.4 and the old one is 2.2.2 in case that's a factor. When the app starts, i...

ruby1.9.1 - sqlite3 problem on ubuntu 9.10 x64 (no such file to load -- sqlite3)

Hi, I have problem with sqlite3, because it is not working. irb(main):001:0> require 'sqlite3' LoadError: no such file to load -- sqlite3 from (irb):1:in `require' from (irb):1 from /usr/bin/irb:12:in `<main>' I have installed following packages: sudo apt-get install ruby1.9.1-full sudo apt-get install rubygems1.9.1 sudo...

RSpec and Cucumber with Rails

After running command "ruby script/cucumber" it produces the error as Using the default profile... e:/Ruby/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/rails/gem_dependency.rb:119:Warning: Gem::Dependency#version_requirements is deprecated and will be removed on or after August 2010. Use #requirement e:/Ruby/lib/ruby/gems/1.8/gems/activesup...

Calculate time elapsed from log timestamps using Ruby

I am parsing a log and would like an elegant way of calculating the difference between these time stamps shown below: [Mar 2, 2010 1:54:40 AM] [Mar 4, 2010 10:54:40 PM] I've looked at DateTime however I wasnt sure if it was ncessary to seperate the Date from the actual time part and create a Time object. If there is an easier way plea...

Debugger in class method ends up in the controller

I have a controller with a action similar to this class EventsController < ApplicationController .... def test Events.first.test end .... end and a model similar to this class Event < ActiveRecord::Base .... def test debugger end .... end What confuses me is that, when the action is tri...

find untranslated locales in rails.

Hi, I'm using rails 2.3.5 with i18n. I's there a way to find all not yet translated locales in all views? Maybe a after_filter in the application controller, but which code I can use for this job? thanks ...

fields_for form builder object is nil

Any way to access a nested form_bulder.object? ## controller @project = Project.new @project.tasks.build form_for(@project) do |f| f.object.nil? ## returns false fields_for :tasks do |builder| builder.object.nil? ## returns true end end ...