ruby

Ruby metaprogramming, how does rspec's 'should' work?

Hi, I was reading up on rspec and I was trying to figure out how rspec's "should" was implemented Could someone give a hand on how the meta nature of this function works? The code is located here: http://github.com/dchelimsky/rspec/blob/master/lib/spec/expectations/extensions/kernel.rb TIA, -daniel Clarification: target.should =...

executing code in rails after response sent to browser

Does Rails provide a way to execute code on the server after the view is rendered and after the response is sent to the browser? I have an action in my application that performs a lot of database transactions, which results in a slow response time for the user. What I'd like is to (1) perform some computations, (2) send the results of ...

Is it possible to create sub-applications in Ruby on Rails 3 or something like slices from Merb?

Does Rails 3 have anything akin to slices in Merb, or areas in Django where there is a layer of organization above the controller? I heard at some point that they may allow hosting one rails app within another but I can't find any information on that in the pre-release material. Any hints on how to do something like this? ...

How is Ruby fully Object Oriented?

So, I'm curious as to how Ruby is a fully object oriented language. I stumble over one problem that isn't really clear to me. If I define a function as follows def foo(text) print text end and I define the function outside of a class, how is this function an object? I realize that I can call foo.class And I get NilClass. Does t...

Has anyone created a debian package for phusion passenger (aka mod_rails) that doesn't depend on rubygems?

As a company policy, rubygems isn't allowed on any of our production servers (which all run debian lenny). All production software must be installed via apt. There is a package for passenger (http://packages.debian.org/lenny-backports/libapache2-mod-passenger), but it depends on rubygems. Before I try to try to hack my own package (pr...

Associating two resources, that are already related

I have three classes that need to be related, and I'm not sure how to do it. The User class, is of course for a user, Game represents a game, GameTurn represents a turn in the game. Game belongs to a user, the user who initiated the game, and GameTurn belongs to a user, the user who played that turn. What I want to do is associate User...

Generating PDF's with signatures using Ruby or Ruby on Rails

I'm working on a Rails application that uses prawn to generate PDF's. Long story short, we want to be able to digitally sign generated PDF's. Im not sure where to start reading up exactly. Just wanted to ask if anybody else has been able to accomplish this before, and if so, what kind of resources I should be using to do it. Thanks! ...

(soap:Server) Server was unable to process request. ---> String reference not set to an instance of a String. Parameter name: s

I am using savon to consume an API. Below are lines from my code. wSDL = "some_wsdl" client = Savon::Client.new(wSDL) response = client.soap_action do |soap| soap.body = "<sample>string_value</sample>" , "<sample1>string_value</sample1>" end I am getting an error (title) and below is the application trace. Btw, my wsdl is i...

Ruby - Validate and update URL

I've been trying to modify this method from redirecting and returning the contents of the url to returning new valid url instead. After reading up on the Net::HTTP object, I'm still not sure how exactly the get_response method works. Is this what's downloading the page? is there another method I could call that would just ping the url ...

In Ruby, how do you print out the URL params and Server environment variables?

In Ruby (running on a web server as a .cgi), how do you print out the URL params and Server environment variables, preferable without using any package? (by the rawest form) ...

In Ruby, is there a way to print out all the Global variables and Constants defined / predefined?

In Ruby, is there a way to print out all the Global variables and Constants defined / predefined? ...

how to use getoptlog in ruby

opts = GetoptLong.new( [ '--help', '-h', GetoptLong::NO_ARGUMENT ], [ '--repeat', '-n', GetoptLong::REQUIRED_ARGUMENT ], [ '--name', GetoptLong::OPTIONAL_ARGUMENT ] ) I have this kind of declaration for optlong. Can anyone tell me if opts works as an array or as a hash and also what are the values in opts. One more thing opts.ea...

In Ruby, if "global_variables.class" returns "Array", how do you tell whether global_variables is an array or a method?

In Ruby, if global_variables.class returns Array, how do you tell whether global_variables is an array or a method? ...

serve current directory from command line

could someone give me a hint, howto serve the current directory from command line with ruby? it would be great, if i can have some system wide configuration (e.g. mime-types) and simply launch it from every directory. ...

How do I use a nested attribute with a form_for 's select method?

We have a user model which :has_one detail. In a form_for a user, I want a drop-down to select the user's details' time_zone. I've tried <% form_for @user do |f| %> ... user stuff ... <%= f.select :"detail.time_zone", ...other args... %> <% end %> but I get a NoMethodError for detail.time_zone. What's the correct syntax fo...

Show nearby cities in a geo location search

I'm developing an app where a user can search by address and get all results within a certain mile radius. I have that part working with the geokit gem and plugin in Rails. But, I'm trying to figure out the best way to to show a list of nearby cities and the number of matches per city. I could iterate over the result set and take out th...

if statement in ruby

How does this statement work? if not a==b puts "amit" else puts "ramit" end Could anybody tell me the use of not operator here? ...

factory girl: association problem testing model which has validates_presence_of accepts_nested_attributes_for

hey, i have a simple associations: class Account < ActiveRecord::Base has_many :users accepts_nested_attributes_for :users validates_presence_of :users end and class User < ActiveRecord::Base belongs_to :account end i just want to run a simple test: describe 'a new', Account do it 'should be valid' do Factory.buil...

packaging rails applications in a gem

i am thinking of releasing a rails application as a gem. it's sort of a wiki application which also stores user data in the db directory. what would be a good way to go to avoid the user data being overwritten, when a gem update is done? example: 1) user gets version 1 of the gem/application. the data is stored in the gem directory. ...

ruby gem install error on MAC pc due to behind corporate proxy

Hi, I am trying to install ruby gems on my MAC (OSX 10.5.1) behind corporate firewall proxy but i am getting error for connection refuse. kindly help me out to resolve this problem. Thanks & regards Ravi ...