ruby

How to prepare an interview for Ruby on Rails developer position?

Background about myself: I have about 3 years experience working in Java/J2EE. I am currently pursuing MS in Software Engineering at a reputed university. I have done several classwork projects on Ruby on Rails and can be considered at Intermediate level expertise with ROR. I have an interview coming up next week for a Ruby on Rails de...

ruby get Time in given timezone

In ruby, how can I get current time in a given timezone? I know the offset from UTC, and want to get the current time in the timezone with that offset. ...

Setting many key/value pairs

Hi, I'm working on a rake task which imports from a JSON feed into an ActiveRecord called Person. Person has quite a few attributes and rather than write lines of code for setting each attribute I'm trying different methods. The closest I've got is shown below. This works nicely as far as outputing to screen but when I check the value...

get last insert id when using Activerecord

Hi, For Sqilte3 C API, I would use sqlite3_last_insert_rowid. How to get this id when using ActiveRecord after insert a new record? I use following way to insert a new record : Section.new |s| s.a = 1 s.b = 2 #I expected the return value of save to be the last_insert_id, but it is NOT s.save end ...

require file use dirname(__FILE__) or just requre filename?

I have a file at lib directory in my rails project. like this a (directory) a1 a2 a.rb when I in a.rb require a1. require 'a/a1' it will warn me /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- a/a1 (MissingSourceFile) but use dirname(FILE), it work. require File.dirname(__FILE...

How to skip certain tests with Test::Unit

In one of my projects I need to collaborate with several backend systems. Some of them somewhat lacks in documentation, and partly therefore I have some test code that interact with some test servers just to see everything works as expected. However, accessing these servers is quite slow, and therefore I do not want to run these tests ev...

How can I create a program to create multiple files from one template with different values inside?

I need to create 1500+ ruby files from a template for some testing I'm doing with Selenium. The template looks like this: class $CLASS_NAME require "spec" attr_accessor :title include Spec::Example::ExampleGroupMethods include Spec::Matchers def initialize @title = "$OLD_URL -> $NEW_URL" end def execute(selenium) selenium....

Ruby AMQP uninitialized constant error

Hi, I was trying out this code (got from an online article here: http://www.randomhacks.net/articles/2009/05/08/chat-client-ruby-amqp-eventmachine-shoes) require 'rubygems' gem 'amqp' require 'mq' unless ARGV.length == 2 STDERR.puts "Usage: #{$0} " exit 1 end $channel, $nick = ARGV AMQP.start(:host => 'localhost') do $chat =...

Top stories in RSS reader

How do you know what are the top stories or hot topics just in RSS feed aggregator NewsNow for example?? Could you please explain? I am new to Ruby on Rails. I want to build a RSS reader in Ruby on Rails. Could you suggest me some good tutorials or links?? Thanks Gautam ...

In Ruby, using Cucumber, should I mock out calls to a webservice?

All, I'm using Cucumber for acceptance testing a Ruby command line utility. This utility pulls data in from a webservice. I understand Cucumber is for acceptance testing and tests the whole stack but I still need to provide consistant replies from the webservice. Should I mock the webservice? If yes, how? What's the best approach here...

jekyll - add stuff to pages automatically, on github pages

Hi! Is there a way to obtain the url of a page on Jekyll? By pages I mean non-post textile files, like about.html and download.html on the following hierarchy: root | +- _includes | +- _layouts | +- _posts | +- _config.yml | +- index.textile | +- about.textile | `- download.textile I'd like to do something like this: <...

File encodings with ruby

Hi, I'm having a bit problems with file encodings. I'm receiving a url-encoded string like "sometext%C3%B3+more+%26+andmore", unescape it, process the data, and save it with windows-1252 encoding. The conversions are these: irb(main) >> value => "sometext%C3%B3+more+%26+andmore" irb(main) >> CGI::unescape(value) => "sometext\303\263 ...

developing facebook applications with ruby: which gems to use?

i am currently planning a facebook application to be developed with ruby on rails. i stumbled upon the facebooker gem, but there seem to be other gems around as well - actually there is also a facebooker2 gem. what are the current options i have with ruby on rails and facebook development? which gems are recommendable? ...

is it right to assigning multiple variable like this a = b = c = d = 5 in ruby?

a = b = c = d = 5 puts (a) >> 5 puts (b) >> 5 puts (b) >> 5 puts (b) >> 5 a= a+1 puts (a) >> 6 puts (b) >> 5 i found there is no problem with the assigning value like this. my question is should one assign like the one given above or a , b, c, d = 5, 5, 5, 5 ...

How to build a Weighted Graph with Ruby's RGL or GRATR to perform Dijkstra's algorithm?

I would like to see an example of a Dijkastra search algorithm for a graph built using Ruby's RGL (http://rgl.rubyforge.org/) or GRATR (http://rubyforge.org/projects/gratr/). I know GRATR has Dijkastra support but I'm not really sure how to go about using it, any help would be appreciated. ...

Ruby GTK fails without display (Python is OK)

it seems that Ruby GTK apps are unable to run in nongraphical environment.. while python apps are able to. oversimplified examples (even without the gtk main loop), demonstrating this behavior: gtktest.py: #! /usr/bin/python import gtk print('the end') gtktest.rb: #! /usr/bin/ruby require "gtk2" puts('the end') X window environme...

validation of special characters

I want to validate login name with special characters !@#S%^*()+_-?/<>:"';. space using regular expression in ruby on rails. These special characters should not be acceptable. What is the code for that? Thanks, Pallavi ...

Is there a way to authenticate a user to LDAP with email/password?

Is there a way to authenticate a user to LDAP with email (mail) and not cn or DN? We are using ruby ldap, and possibly active-ldap (we have been having problem with it, though). All we need to do is authenticate a user and then create a membership in our system based on the authentication success. ...

How to insert rows in a many-to-many relationship

Hello, I am having an issue trying to save into an intermediate table. I am new on Rails and I have spent a couple of hours on this but can't make it work, maybe I am doing wrong the whole thing. Any help will be appreciated. =) The app is a simple book store, where a logged-in user picks books and then create an order. This error is ...

What's a good plugin or guide I can use to create javascript widgets from a Rails App?

I've been looking around for a while now and the best guide I've seen so far is Dr Nic's DIY widgets how to (here). I haven't been able to make something like this work: Assuming this is my widget code: <script src="http://mysite/nomnoms.js"&gt; </script> And my nomnoms controller looks like (assume that the list partial exists and...