ruby

Distributing Rails Applications as Native Applications

I would like to distribute a rails application as a double clickable application. When someone double clicks on the app, I think that mongrel should be started and then the user's browser should be started and open to something like localhost:3000 I'm trying to work through what I will need to do this, I think I'm going to need to incl...

Make blank params[] nil

When a user submits a form and leaves certain fields blank, they get saved as blank in the DB. I would like to iterate through the params[:user] collection (for example) and if a field is blank, set it to nil before updating attributes. I can't figure out how to do this though as the only way I know to iterate creates new objects: col...

(Ruby) Getting Net::SMTP working with Gmail...?

Hi All, Does anyone have any quality (and up-to-date) information regarding sending mail via Gmail using Ruby's Net::SMTP? I've seen several examples -- most dating from 2007 to mid-2008 and none of them work for me. I need more current examples that use the most recent 1.8.7 release. I'd also appreciate if the documentation didn't o...

Making a SOAP request by using XML in Rails

I want to make a request to a SOAP Web Service but I don't want to install any gems. Is there any way to just make the request using plain XML? I think it's trivial but there might be something I've missed, because all implementations/tutorials were using a gem. I think that the SOAP response, can be handled also as a XML response rig...

How to update Ruby version in Window?

Hello, everyone. I am trying to install an Amazon Web service gem into my project (I use window and Aptana RadRails) but it asked me to update current Ruby version (1.8.5) to 1.8.7. I use InstantRails for Window platform. So could you tell me how can I upgrade my Ruby to new version? Do I need to install new InstantRails? or Can I upd...

What's the purpose of singleton_class.send & singleton_class.class_eval in this metaprogramming example?

class Product < ActiveRecord::Base set_table_name 'produce' end module ActiveRecord class Base def self.set_table_name name define_attr_method :table_name, name end def self.define_attr_method(name, value) singleton_class.send :alias_method, "original_#{name}", name singleton_class.class_eval do define_method(name) do value en...

What is the purpose of lambda in this example?

lambda is used in this example in both the compose and the hydrate methods. What does lambda do here? def compose *lambdas if lambdas.empty? lambda { nil } elsif lambdas.size == 1 lambdas.first else lambda do |n| lambdas.first.call(compose(*lambdas[1..-1]).call(n)) end end end def hydrate(modulus, printabl...

About the RoR Update DB Record

I would like to use the ruby on rails and mysql to write a simple test program but, in this time, i can not update the database record. because i use the "mid" to replaced the "id" column in this case, what can i do to work to update the record? Problem: Mysql::Error: Unknown column 'id' in 'where clause': UPDATE `messages` SET `messag...

Using ruby and nokogiri to select ahrefs based on part of the URL

I have a document containing ahref links I want to extract. The link I want can be identified by part of the url they link to. There are other links that are similar which I want to discard. The urls of the links I want are of the format http://www.xxxxxxxxxxxxxxxxxxx.com/index.php?showtopic=44&amp;hl= I want to search for links con...

Calculating item counters for a set of selected categories.

In our Ruby on Rails project we have a lot of categorization criteria for recipes, such as cook method, occasion etc. Every recipe belongs to one or several of these categories. When someone starts browsing for recipes, he/she can narrow down to a set of particular categories. Then we need to calculate the number of recipes in all catego...

Can't install gems that depend on hoe

I can't seem to install the twitter gem in my shoes app. When I try... Shoes.setup do gem 'twitter' end require 'twitter' I get hoe requires RubyGems version >= 1.3.1 Is this a bug in Shoes or Hoe? Any ideas on a work-around? ...

Access error occured in Ruby 1.9 + MySQL

I can't connect mysql db with ruby1.9 OS -> Windows XP SP2 Ruby -> 1.9.1p0 dbi -> 0.4.2 dbd-mysql -> 0.4.3 MySQL API module for Ruby -> 2.7.3 DB(MySQL) -> 5.1.34-community Because msvcrt-ruby18.dll was not found, I was not able to start this application. What's wrong ...

jQuery can't parse JSON built with Ruby-JSON

I'm trying to set up an Ajax callback using jQuery, and it's just not working. My Ruby code looks something like this: return {:one => some_html, :two => more_html}.to_json When it gets to the client jQuery bails saying "parse error". If I make it something really simple, like: return {:one => 'Something', :two => 'Something else'}.t...

Correct Way to Set Default Values in Rails

I'm trying to find the "best" way to set default values for objects in rails. Best I can think of is to set the default value in the "new" method in the controller. Anyone have any input on if this is acceptable or if there's a better way to do it? ...

Good resource to learn BDD, TDD (ruby , C#, javascript)

What are the good resource to learn BDD & TDD (ruby , C#, javascript). What are the good framework using now? ...

Multivariable Partial in Ruby on Rails

I have a partial that I want rendered with a collection and another variable. Is it possible to pass more than one variable to a partial? To illustrate: Category HABTM Brands This is just semi-pseudo-code, but I want to do something like: <% @categories.each do |c| %> <%= c.name %> <%= render :partial => "mypartial", :collec...

Regular expressions in cucumber steps

Cucumber generates out some neat webrat regex steps. I encountered a problem when I tried the this. In feature: And I fill in "Telephone (Home)" with "61234567" In webrat steps: When /^I fill in "([^\"]*)" with "([^\"]*)"$/ do |field, value| fill_in(field, :with => value) end The error encountered: Could not find field: "Telep...

Getting a User Input In Ruby

Hi, I have a quick question in Ruby Lets say I ask the user to enter a name ( for a new class that i want to create) my code is: puts "enter the name for a new class that you want to create" nameofclass = gets.chomp nameofclass = Class.new Why does this not work? Also, I want to ask the user to enter the name of a method that i wan...

How do I check If a Class already exists in Ruby

How do I check If a Class already exists in Ruby, My code is: puts "enter the name of the Class to see if it exists" nameofclass=gets.chomp eval (" #{nameofclass}...... Not sure what to write here") I was thinking of using: eval "#{nameofclass}ancestors. ....." ...

Ruby on Rails - Can I modify data before it is saved?

Quick example: A user enters a username into a form, and I need to make that text username before storing it in the app's database, thereby making it permanently lowercase. Where would I put this code, and how would I access the data to be lowercased? Thanks. ...