ruby

How can I view HTTP requests being sent through a rails application?

I'm trying to interface with a 3rd party website, and the communication goes as follows. Send this request POST /Service/LabelService.asmx/GetLabelXML HTTP/1.1 Host: www.host.com Content-Type: application/x-www-form-urlencoded Content-Length: length labelRequestXML=<LabelRequest> ... </LabelRequest> Receive this response HTTP/1.1 ...

Writing an ActiveRecord adapter

I'd like to write my own ActiveRecord adapter for the HBase database since none currently exist. However, I've been searching for a while online and can't find any good resources on how to write an ActiveRecord adapter. How would you go about doing this, or are there any links you can recommend? ...

Ruby solitaire game

I would like to build a simple standalone solitaire game in ruby. Are there any libraries I should use? Do I even need game libraries to have cards moved from one stack to another? I have never written any games, and I haven't built a standalone app for a long time, that's why I'm lost :) ...

How can default values in Sequel Models be set?

Given the code below, how can default values be defined for the Model. (let's say the default for :name should be 'Thing'). require 'pp' require 'sequel' DB = Sequel.sqlite DB.create_table :items do primary_key :id String :name end items = DB[ :items ] class Item < Sequel::Model end Item.create :name => 'foobar' Item.create ...

python and ruby - for what to use it?

Hi, I'm thinking about learning ruby and python a little bit, and it occurred to me, for what ruby/python is good for? When to use ruby and when python, or for what ruby/python is not for? :) What should I do in these languages? thanks ...

Compiling Ruby 1.9.1-p129 on HPUX

I am trying to compile Ruby on HPUX but get the following: cc: "transcode.c", line 1489: error 1588: "SIZE_MAX" undefined. cc: "transcode.c", line 1489: error 1563: Expression in if must be scalar. ...

ruby 1.9 methods in ruby 1.8.6

Is there a gem or a library to get ruby 1.9 methods like [1, 2, 3].combination(2) [1, 2, 3].permutation(2) [1, 2, 3].product([1, 2, 3]) [1, 2, 3, 4, 5].cycle ...

initializing and incrementing a variable in one line of code

Is this the DRYest way to do it in ruby? <% for item in @items %> <%= n = n + 1 rescue n = 1 %> <% end %> which initializes "n" to '1" and increments it as the loop progresses (and prints it out) since this is in one my app's views ...

How do you send plaintext instead of HTML email from Rails?

I'd like to send plain text emails from a Rails app. In my mail sending config I have: ActionMailer::Base.default_content_type = 'text/plain' Nonetheless, when I send a test email from the Rails console, I get: >> GeneralAppMailer.deliver_test # ... Content-Type: text/html; charset=utf-8 And looking at it in Gmail, it does seem t...

Is there a way to predict unknown function value based on its previous values

I have values returned by unknown function like for example # this is an easy case - parabolic function # but in my case function is realy unknown as it is connected to process execution time [0, 1, 4, 9] is there a way to predict next value? ...

running arbitrary system commands from Ruby, on OSX and Windows

I would like to open OSX windows (and Windows windows) from a ruby script. If I do system "touch /Users/apple/Documents/thekbase-temp-files/test5.txt" it works (creates an empty file), but this system "mate /Users/apple/Documents/thekbase-temp-files/test5.txt" does not open TextMate, even though it does if I type it. I feel this mi...

Rails, trouble in a form trying to use the put http method

<% form_ tag user_path(@user), :method => :put do %> That's my form, so I want it to access the update method of my UsersController, I set the map.resources :users , and the RESTful paths generated: users GET /users(.:format) {:action=>"index", :controller=>"users"} POST /users(.:format) {:a...

How do you get libcurl libraries to work with InstantRails?

I'm working on a windows machine and trying to get the curb plugin to work, first thing I realized was I needed the curl library installed on my machine, so that's what I'm looking to do. I simply downloaded a curl library, a curllib library, and have them located at c:/curl and c:/curllib respectively. I setup my environmental variabl...

Best Rails Tagging Plugin/Gem

Hello, what plugin or gem do you recommened for tagging? There are many of them, acts_as_taggable, acts_as_taggable_on_steroids, acts_as_taggable_on,... What do you say? ...

Updated (current) recommendation on Rails versus Django?

(Disclaimer: I asked this question yesterday on HN http://bit.ly/m6onk. While responses were good, there was a notable lack of technical discussion and more of a "you should use rails because that's what you know". Since Joel and Jeff state clearly they don't mind reposts of questions from other sites...and since I really enjoy the answe...

how best to refactor two classes with lots of conditional logic?

hi! I have an Event class which holds start and end times for an event. Each Event object can have a number of associated ChildEvent objects representing each recurrence of the parent Event. Each of those classes needs to take a different action based on how they are being edited e.g. Deleting just one Event: Event: make the first ch...

How to make Ruby's N ends look better?

As I write some scripts, I usually reach a point where my code looks like this : end end end end end end I don't know about you, but this look very ugly to me. Can something be done about this? ...

Ruby Template Module

Assume I have a family of related modules: module Has_Chocolate def has_chocolate? true end end module Has_Cake def has_cake? true end end . . . How would I construct a template module Has_*Something* where Something would be a parameter to the module? ...

How do I apply border to a flow on click?

I've got this piece of Shoes app: flow :top => 10, :left => 10 do flow :width => 0.3 do para @board.deck.card click do if @board.source_pile @board.source_pile = nil @deck_border.hide else @board.source_pile = @board.deck @deck_border = border yellow, :strokewidth => 2 end ...

Reject Non-localhost Attempts to Access Webrick

I'm trying to block all non-localhost attempts to access a Webrick process. This is my current code def do_GET(req, res) host_name = "localhost:3344".split(":")[0] if host_name != "localhost" && host_name != "127.0.0.1" puts "Security alert, accessing through #{host_name}" return else puts "we're fine, #{...