ruby

controller and restful application

Hello, I have a MVC web application (Ruby, Rack, Apache) and I want it to be restful. I have a dispatcher that will get incoming URI and call the appropriate controller. In my mind, a controller is there to handle every actions linked to a single model, I am wrong ? The thing I am not sure about is a case like the following: If a user h...

Given a path, how to determine if its absolute/relative in Ruby ?

I am working on writing a rake build scrip which will work cross platform ( Mac OSX, Linux , Windows ). The build script will be consumed by a CI server [1] I want the logic of my script to be as follows: If the path is determined to be relative, make it absolute by making *output_path = FOO_HOME + user_supplied_relative_path* If th...

TeamCity returns No such file to load -- rubygems (LoadError) but terminal runs fine

I've just setup 3 osx agents to run the CI for our ruby project. 2 of these agents are running our specs perfectly, starting their agents correctly etc. The third machine constantly returns No such file to load -- rubygems (LoadError). I have navigated to the work folder (the check out folder for the project) and i can run the commands i...

convert from a 2d array to nested_set in Ruby on rails

I have a tree structure in a .csv file (nodes are of type text), and after reading the csv i want to store the data in a ruby object. I went through a few tree plugins and i think nested_set would serve the purpose for me. However, i am facing problem with fixing a format of csv file, so that i can read it and convert into tree object. I...

is it good programming practice to put code statements in braces?

I have never seen this being done anywhere in all the source code i've read in my life. If it is considered bad programming practice, there has to be a reason for it which i fail to understand. Also, I think it sometimes improves readability rather than worsening it. Here are a few places i've done it in my ruby code. @pushButton.conne...

Complex joins with legacy tables in Rails

Hello, I'm writing fairly simple web interface for invoice/customer/contract database. I would like to have the following structure for my models: class Invoice < ActiveRecord::Base set_table_name 't10_invoices' set_primary_key 'id_invoice' has_one :client end class Client < ActiveRecord::Base set_table_name 't20_clients' ...

Rails: list all plugin paths

I'd like to enumerate the paths for all of the plugins in a Rails application. Essentially #{RAILS_ROOT}/vendor/plugins/*, but that does not include plugins provided by gems, or specified explicitly, et cetera. I've found one solution which I'll provide in an answer so you can vote for it, but it's pretty ugly. (Is that the proper eti...

How to test a Singleton class?

Hi, I am using RSpec and want to test the constructor of a Singleton class more than one time. How can I do this? Best regards ...

Mechanize Ignore Javascript when Required by Page

Hello, I understand a few people have asked about JS support in Mechanize. My question might be a little bit different, and/or posed differently. I am looking to ignore the Javascript check and log in to a page that requires Javascript. The web site itself does not really need JS, but the developers felt they needed to require it for th...

Ruby 1.9: how to properly upcase/downcase multibyte strings?

So matz took the questionable decision to keep upcase and downcase limited to /[A-Z]/i in ruby 1.9.1. ActiveSupport::Multibyte has long had great i18n case jiggering in ruby 1.8.x via String#mb_chars. However, when tried under ruby 1.9.1, it doesn't seem to work. Here's a simple test script I wrote, along with the output I'm getting: ...

Ruby twitter example - Client must provide a 'status' - Content-Type issue

Got the following error when using Ruby irb to test simple twitter status update ... #<Net::HTTPForbidden:0x2ca15dc> <?xml version="1.0" encoding="UTF-8"?> <hash> <request>/statuses/update.xml</request> <error>Client must provide a 'status' parameter with a value.</error> </hash> Code used was: twitHeaders = { "Content-Type"=>"...

Ruby + QT4; how to start

trying to add QtRuby support on my gentoo linux.. i dont find any qt gem in repository download qt4-qtruby but cmake fall.. please say right way to setup.. ...

How can I Parse an HTML response without response headers using Ruby

How can I grab an HTML response when there are no response headers? I've got this: require 'hpricot' require 'open-uri' doc = Hpricot(open('http://192.168.100.1/phy.htm')) The server in this case is a cable modem that is not returning HTTP Response headers. The above code is failing with: C:/Ruby/lib/ruby/1.8/net/http.rb:2022:i...

How do I generate a tournament schedule in Ruby?

I have been searching everywhere, including the Stack Overflow archives, for an answer of how to do this, I tried rolling my own, but have come up short, so I decided I would post my request here. I need to take an arbitrary (even) number of items in an array and return with item paired with another item in the array. I need the output ...

Ruby on Rails - generating column for textarea and pics

I am new to rails so excuse the simple questions. I am creating a website for a company. That company wants to display it's clients on the site. I would like to allow the client to manage this themselves. I am generating a table for the 'clients' and the three columns I would like to have are: Company Name, Company Description and logo...

trying to find a file/line for: .(eval):289: warning: don't put space before argument parentheses

So, I get this warning when I'm running my tests in ruby/RoR .(eval):289: warning: don't put space before argument parentheses I've checked every where (but obvoiusly not) and I can't find the origin of this error. The above error just pops up inbetween the unit tests ... Can someone clue me in onto how to find the location of this e...

Has anyone gotten the LinkedIn Ruby Gem to work at all?

The ruby gem for LinkedIn that I'm using is here: http://github.com/pengwynn/linkedin When calling LinkedIn::Client.new with a valid API Key and Secret, I get this: undefined method `tap' for # Other people have had the same problem, see http://developer.linkedin.com/message/2363 Don't think anyone has proposed a solution yet. ...

Rendering as hyperlink Ruby on Rails...

I am new to rails so sorry for stupid questions. I have created section of the website I am working on where the client can post news about their clients. In the entry view I collect title:string content:text and link:string. How do I render the link:string as an actual link in the show and index views. ...

Dropdown Box Ruby on Rails question...

I am new to rails so go easy. I have two tables that I am trying to work with here, 'post' and 'category'. The 'post' table includes the following columns, title:string content:text category:string. The 'category' table simply contains name:string. The idea is that the client can manage the categories and also when adding a new post,...

Displaying Paperclip Image in index.html.erb view...

I have successfully followed Ryan Bates tutorial of paperclip and have it working correctly. The image attaches to the record and displays on the show.html.erb.I am wondering how to display it on the index pages. Below is what I have tried but not working. For reference, the table is 'review' and the photo is 'photo'. <table> <tr> ...