ruby

Ruby: Is a string in a list of values

Newbie Ruby question: I'm currently writing: if mystring == "valueA" or mystring == "ValueB" or mystring == "ValueC" is there a neater way of doing this? ...

Question about Cucumber/Pickle

Hi, I'm trying to get a little more familiarity with Rails / ActiveRecord. In trying to do so I am attempting to use Cucumber to help with some "discovery" tests. I have the following Feature: Describing a task In order to work with tasks As a user I want to be able to know what makes up a task and to improve my understanding ...

Ruby on Rails - One model can see module, another cannot?

Hi, I have a simple module for adding the current user to a newly created object: module AttachUsers def create_with_author(author, params) created = new(params) created.author = author created.save created end def create_with_author_and_editor(author, params) created = new(params) created.author = author...

comparing params in rails

I am doing if params[:type] = "Type A" # do something end if params[:type] = "Type B" # do something end But I think that is wrong. I should be using == However that gives me error: You have nil object when you didn't expect it What is the best way to do this in rails? All I am doing is getting a radio button variable from ...

Rails: A good search algorithm

I'm trying to return results more like the search My curren algorithm is this def search_conditions(column, q) vars = [] vars2 = [] vars << q if q.size > 3 (q.size-2).times do |i| vars2 << q[i..(i+2)] next if i == 0 vars << q[i..-1] vars << q[0..(q.size-1-i)] vars << q[i % 2 == 0 ? (i/2)..(q...

Rails and Hobo with Single Table Inheritance problem

I'm getting an error when running db:setup for my Hobo project with a clean database. I have two models, A and B, where B extends A through single-table-inheritance. Creating everything works. But if I start with a fresh database, rake fails with an error: $ rake db:setup ... rake aborted! Table as does not exist Here are the steps I ...

Watir - Manual POST request

Hello, Scenario: I have logged into a website, gained cookies etc, got to a particular webpage with a form + hidden fields. I now want to be able to create my own http post with my own hidden form data instead of what is on the webpage and verify the response instead of using the one on the webpage. Reason: Testing against pre-exis...

How can you interact with Perl programs from Ruby?

It's my understanding that there's no "bridge" between Ruby and Perl to let you call into Perl functions directly from Ruby. It's also my understanding that to call a Perl program from Ruby, you simply put it in backticks(i.e. result = `./helloWorld.pl`). However, this doesn't allow interaction with the Perl program(i.e. you can't intera...

phusion passenger and ruby 1.9.1 is it working already?

i have a production and a development machine, both running ubuntu 8.10 and both are running the latest phusion passenger. as i am using ruby 1.9.1 on my local development machine on osx, i wondered if people out there are already using phusion passenger with ruby 1.9.1 or even 1.9.2 already? if so, please tell us your setup! furthermor...

extract single string from html using ruby/mechanize (and nokogiri)

I am extracting data from a forum. My script based on is working fine. Now I need to extract date and time (21 Dec 2009, 20:39) from single post. I cannot get it work. I used FireXPath to determine the xpath. Sample code: require 'rubygems' require 'mechanize' post_agent = WWW::Mechanize.new post_page = post_agent.get('http:/...

Picking a database technology

We're setting out to build an online platform (API, Servers, Data, Wahoo!). For context, imagine that we need to build something like twitter, but with the comments (tweets) organized around a live event. Information about the live event itself must be delivered to clients as fast and consistently as possible, while comments about the ev...

How can I decide my browser (*firefox,*ie) from command line in the rake file?

I have a rake file which runs few tasks. I want to run my tests on several browsers without hard-coding it on each test. Any suggestions would be great. ...

Nanoc3 site creation estimation

I am asked to create a few small websites using nanoc3 like http://www.pancakeaircompressor.org/, how long does it take? I am quite familiar with Ruby & HTML. ...

Tips for rails blog

I'm looking for some blog that talks about ruby and rails. Any tips? Thanks ...

Ruby on Rails - Rounding ones, tens and hundred digit places

hi, I want to round of the ones and tens digit positon for the value.. if it is 1999, it should display as 1900 and if it is 19999 it should display as 19000 code goes like this {overall_cost.to_money.format(:no_cents)} ...

What is the absolutely cheapest way to select a child node in Nokogiri?

I know that there are dozens of ways to select the first child element in Nokogiri, but which is the cheapest? I can't get around using Node#children, which sounds awfully expensive. Say that there are 10000 child nodes, and I don't want to touch the 9999 others... ...

Ruby core extensions with modules

Basically I have two modules: CoreExtensions::CamelcasedJsonString and …::CamelcasedJsonSymbol. The latter one overrides the Symbol#to_s, so that the method returns a String which is extended with the first module. I don't want every string to be a CamelcasedJsonString. This is the reason why I try to apply the extension instance specifi...

Programmatically Log/Tail Browser Activity with Ruby to a File?

How do I access this activity log information programmatically with Ruby (this is the Activity Window from Safari)? Can I use Mechanize to spit out all this information (duration, size, address, etc.) in XML, or is this already stored somewhere on my computer? ...

Access Ruby accessors using block variables

I have an application that I am using Active Record to access a database. I'm trying to take the information and put it into a hash for later use. Here is basically what I am doing. require 'active_support' @emailhash = Hash.new emails = Email.find(:all) emails.each do |email| email.attributes.keys.each do |@co...

Ruby and console output

It is possible, generally, by means of Ruby library to output a symbol at specific location on a common Windows console screen, which seems to be 80x25 ? The problem came up with the need to draw a specific 'tree' structure like this, for example: │ ├──x──y──z │ │ │ ├──a──b──c │ │ │ └──e──f──g │ └──u──v──o ...