ruby

How do I set a custom path in textmate to find my ruby files?

I'm new to programming and trying to learn Ruby through some online tutorials. I have textmate and have created a Ruby folder in my Documents folder to hold my .rb files. While working through "Why's Poignant Guide" I came a across a two file program. One file attempts to 'require' the other. However, this doesn't work in this folder. Is...

Iconv.conv in Rails application to convert from unicode to ASCII//translit

We wanted to convert a unicode string in Slovak language into plain ASCII (without accents/carons) That is to do: č->c š->s á->a é->e etc. We tried: cstr = Iconv.conv('us-ascii//translit', 'utf-8', a_unicode_string) It was working on one system (Mac) and was not working on the other (Ubuntu) where it was giving '?' for accented chara...

Gem install on Windows 7

Try to install feedzirra gem (http://github.com/pauldix/feedzirra) Do this: gem install pauldix-feedzirra I get the following error: Temporarily enhancing PATH to include DevKit... Building native extensions. This could take a while... ERROR: Error installing pauldix-feedzirra: ERROR: Failed to build gem native extension. ...

What is a very simple authentication scheme for Sinatra/Rack

I am busy porting a very small web app from ASP.NET MVC 2 to Ruby/Sinatra. In the MVC app, FormsAuthentication.SetAuthCookie was being used to set a persistent cookie when the users login was validated correctly against the database. I was wondering what the equivalent of Forms Authentication would be in Sinatra? All the authentication...

Generating many almost identical ruby unit tests

I have a number of ruby files (a.rb, b.rb, c.rb) which define very similar classes. (They should test the same) I've written a unit test to test these subclasses and I've generated contexts for each of the classes programatically (see below) — should I instead programatically create entire Test Classes instead? If so why and how? I'm u...

Changing params for search with rails and sunspot

This seems like a common task, I'm sure others have come across it. If my controller says this : def index s = Sunspot.search Organization do |query| query.keywords params[:q] unless params[:q].blank? query.with(:searchable).equal_to(params[:filter_by] == 'published' ? 'true' : false) if params[:filter_by] .. How do I: ....

Blocks & Procs in Ruby

Hi there, I have started learning Ruby, and I have read a couple of tutorials and I even bought a book ("Programming Ruby 1.9 - The Pragmatic Programmers' Guide"), and I came across something new that I haven't seen before in any of the other languages I know (I am working as a PHP webdeveloper). Blocks & Procs. I think I understand wh...

Hpricot and Rails

I am completely new to Ruby and Rails... in fact I created my first application in Rails today that makes an HTTP request to pull back an XML document and then outputs it to the screen.. something simple to get started.. Well I am needing to now parse the XML string but am lost on how to do that exactly with Hpricot. Here is my code so...

Candlestick/Financial Charts in Ruby

Are there any good libraries available for plotting candlestick and other types of financial charts in Ruby? I saw this similar post from over a year ago. The presented options that fit my needs from that post were Python, however. EDIT: One requirement is that I need real-time charts, updating multiple times a second. ...

replace every occurrence of 'line 2' with line_2 with regex

I'm parsing some text from an XML file which has sentences like "Subtract line 4 from line 1.", "Enter the amount from line 5" i want to replace all occurrences of line with line_ eg. Subtract line 4 from line 1 --> Subtract line_4 from line_1 Also, there are sentences like "Are the amounts on lines 4 and 8 the same?" and "Skip lines 9...

Force fake response using ActiveMerchant response

have a transaction model similar to RailsCasts ActiveMerchant tutorial. How can I create a fake response? Tried something like the following but no luck. response = @success=true, @params = {"ref" => "123"}, @authorization = "54321", ... models/order_transaction.rb class OrderTransaction < ActiveRecord::Base belongs_to :order ...

Which gem do you recommend for spidering a web site

Hi, Which gem do people recommend for assisting me with spidering round a website. I have come across mechanize or Anemone and wonder if anybody can point me in the right direction. Mecahnize seems to be the more popular but anemone seems nice also. Thanks Paul ...

Using helpers in rails 3 to output html

Guys, I'm trying my best to build a helper that outputs a <'ul> consisting of all the members of a collection. For each member of the collection I want to print out a <'li> that has a title, and a div of links to CRUD the member. This is pretty similar to what Rails outputs for scaffolding for the index view. Here is the helper I've ...

parse a CSV, update a field, then save

I have everything working fine except saving my changes to the field im updating: require 'csv' @parsed_file = CSV::Reader.parse(File.open("#{RAILS_ROOT}/doc/some.csv")) @parsed_file.each_with_index do |row, x| address = row[5] l = Location.address_find(address) if l != nil puts "#{l.name} at #{l.address}" row[14] = l.sto...

Ruby and :symbols

Hi. I have just started using Ruby and I am reading "Programming Ruby 1.9 - The Pragmatic Programmer's Guide". I came across something called symbols, but as a PHP developer I don't understand what they do and what they are good for. Can anyone help me out with this? ...

ruby ping for 1.9.1

I want to ping a site in my ruby code and saw that net-ping was a nice library to do this with. Unfortunately, when I tried to gem install net-ping I got the following error: C:>gem install net-ping ERROR: Error installing net-ping: win32-open3 requires Ruby version < 1.9.0. upon further research, I found that net-ping was not...

Which MongoDB DSL should I learn?

Im using MongoDB and Ruby. I have noticed there are different DSL:s. The Javascript DSL used with the MongoDB client (mongo): show dbs use my_db db.person.find({first_name: "Syd"}) The Ruby DSL used with the Ruby driver for MongoDB: connection = Mongo::Connection.new connection.database_names.each { |name| puts name } connection.da...

Beautify HTML code using Ruby or Java?

I'm looking for pure Ruby (or Java) solutions for beautifying HTML code. I'm currently using Hpricot to parse HTML, since Nokogiri and other HTML parsers require external C programs. I assume that I can use Hpricot to clean up HTML if I can come up with a good algorithm. I'd prefer not to reinvent if this has already been done. ...

How do I make a method available to both my controller and model in Rails?

I have a private method in my Rails app to connect to Amazon S3, execute a passed block of code, then close the connection to S3. It looks like so; def S3 AWS::S3::Base.establish_connection!( :access_key_id => 'Not telling', :secret_access_key => 'Really not telling' ) data = yield AWS::S3::Base.disconnect data end...

.collect on a belongs_to raising NoMethodError: undefined method `add' for nil:NilClass

Setup: Rails 3 RC2, Ruby 1.9.2 p0 (also tried on Rails 3 beta 4, Ruby 1.8.7 p174) I have quite a basic shopping cart setup: Order has_many :order_items Order has_many :products, :through => :order_items, :dependent => :restrict Product has_many :order_items Product has_many :orders, :through => :order_items, :dependent => :restrict O...