ruby

Ruby on Rails offline programming

I am going to be away from the internet for a few weeks and would still like to get a project done. What steps should I take to make sure I have access to the things I need (ruby and ROR) while I will be disconnected? ...

Beginner += in Ruby

Looking at this block, I can follow the whole program until I hit, sum += square. What is he point of this line, what does it say??? sum = 0 [1, 2, 3, 4].each do |value| square = value * value sum += square end puts sum ...

Are Ruby formatted strings and interpolated strings identical in behaviour?

Do the following two lines of code behave in exactly the same way despite slightly different implementations values.map{ |k,v| __send__('%s=' % k.to_s, v) } values.map{ |k,v| __send__("#{k.to_s}=", v) } The second line would be a more common ruby idiom so I was wondering why the other method was used when this was in the Rails Core wh...

Fix an external dependency of a ruby gem

I am currently trying to install the gem nfoiled, which provides a ruby interface to ncurses. I do this by using gem install elliottcable-nfoiled as suggest in the README. Downloading it manually from the github repository and then installing it with rake install doesn't work because of a problem with the echoe-gem, thus I am bound to us...

functional test for rails controller private method

I have a private method in my controller. which is used for some database update. this method i am calling from another controller method. and it works fine. But when i am trying to write a test case for that method then It is tripping on accessing (session variable and params) in my functional all other methods are working fine the pro...

Exclude draft articles from Solr index with Sunspot

I have an indexed model called Article and I don't want solr to index unpublished articles. class Article < ActiveRecord::Base searchable do text :title text :body end end How can I specify that article that is not #published? should not be indexed? ...

Authentication Problem - not recognizing 'else' - Ruby on rails...

I can't seem to figure out what I am doing wrong here. I have implemented the Super Simple Authentication from Ryan Bates tutorial and while the login portion is functioning correctly, I can't get an error message and redirect to happen correctly for a bad login. Ryan Bates admits in his comments he left this out but can't seem to imple...

Wrapper around bash, control STDIN and STDOUT

I would like to talk to a interactive bash process. Here is an example, so you know what I want to archieve: Program starts a new bash process. User types "ls" into my program. Program sends this command to the bash process. Program reads all available output of the bash (including the prompt) and displays it back to the user. GOTO 1 ...

Ruby: How to get the first character of a string

How can I get the first character in a string using Ruby? Ultimately what I'm doing is taking someone's last name and just creating an initial out of it. So if the string was "Smith" I just want "S". ...

Rails validates_length_of is misbehaving

Hi I have a rails model that I am adding validations to and I seem to have run into a bit of weirdness from one of the validators. So here is the table I am working with (From schema.rb): create_table "clients", :force => true do |t| t.string "name" t.string "last_contact" t.integer "contacting_agent" t.date ...

Way to partially match a Ruby string using Regexp

I'm working on 2 cases: assume I have those var: a = "hello" b = "hello-SP" c = "not_hello" Any partial matches I want to accept any string that has the variable a inside, so b and c would match. Patterned match I want to match a string that has a inside, followed by '-', so b would match, c does not. I am having problem, because...

Formtastic, own :as input type

How I can add my own field types to formtastic ? For exemple, I need to have a custom datetime input, and I want something like this: <%= f.input :start_date , :as => :my_date %> This obviously doesn't work because formtastic doesn't know the :my_date (only :boolean, :string, :datetime and so on...) But how can I add additional inpu...

Action Mailer Confirmation Emails - Ruby on Rails...

I have successfully installed the Clearance Gem from ThoughtBot. Clearance sends a confirmation email upon a new sign_up and suggests adding: config.action_mailer.default_url_options = { :host => 'localhost:3000' } to your /environments/test.rb and development.rb. I have tried this and also config.action_mailer.default_url_options =...

google search as an rss feed

Hi guys, Is there a way to have treat google serach results as an rss feed? For example say I worked for stackoverflow and wanted to montior how if the results from the following search url: http://www.google.com/search?hl=en&amp;q=stackoverflow changes from day today. It would be cool if I could append &output=rss to the url and get ...

Ruby get nth item from massive range

Suppose I have this range: ("aaaaa".."zzzzz") How would I get the Nth item from the range without generating the entire thing before hand/each time? ...

Using ruby's OptionParser to parse sub-commands

I'd like to be able to use ruby's OptionParser to parse sub-commands of the form COMMAND [GLOBAL FLAGS] [SUB-COMMAND [SUB-COMMAND FLAGS]] like: git branch -a gem list foo I know I could switch to a different option parser library (like Trollop), but I'm interested in learning how to do this from within OptionParser, since I'd like ...

intelligent thin start with port alias for bash

i would like a single alias (ts) which starts my local development server. the script should test for an open port starting at 3000 and use the first available port. additionally, some sites require a rackup file, making -R config.ru necessary. this script should check the current directory for the config.ru file and add that to the alia...

bidirectional habtm linking

Hi, all. I have application with 2 groups of models - content based (news, questions) and "something" based (devices, applications etc). I need to link all models between groups - for example question may belongs to 3 different things - one application and 2 devices. The same - for news. From other side - i need to see all news articles ...

urldecode in ruby ?

how do i transform www.bestbuy.com/site/Electronics\Audio\abcat0200000.c=3fid=3dabcat0200000 into its original format ? www.bestbuy.com/site/Electronics/Audio/abcat0200000.c?id=abcat0200000 urldecode ? ...

Problem with activesupport ruby 1.91 and rake

I have an installation of ruby 1.9.1 ruby 1.9.1p378 (2010-01-10 revision 26273) [i386-mingw32] when I try and run a rake task I am getting an error: rake aborted! no such file to load -- ftools C:/Ruby/lib/ruby/gems/1.9.1/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:156:in `require' C:/Ruby/lib/ruby/gems/1.9.1/gems/act...