ruby

Can't get PayPal Encrypted Website Payments to work in Rails

Hi all, I am having problems getting PayPal Encrypted Website payments to work on a Rails site. I am getting two different error messages when posting to the PayPal URL - on my staging site, which uses the sandbox, I am getting: The certificate has been removed. Please use a valid certificate. Whereas on the production site, I ge...

Encoding in Ruby 1.8.7 or 1.9.2

I have been trying to use the gem 'character-encodings' which doesn't build in 1.9.2 however it does in 1.8.7 but even when I require 'encoding/character/utf-8' I still cant do the simplest of encoding. require 'encoding/character/utf-8' str = u"hëllö" str.length #=> 5 str.reverse.length #=> 5 str[/ël/] #=> "ël" I get ruby-1....

Help with Ruby Koans #6 - What exception has been caught?

I'm trying to learn Ruby through Koans but I'm stuck on the 6th step. Here's the code: def test_you_dont_get_null_pointer_errors_when_calling_methods_on_nil # What happens when you call a method that doesn't exist. # The following begin/rescue/end code block captures the exception and # make some assertions about it. ...

Marshal ruby hash with default proc - remove the default proc?

I've got a Hash with a default proc that I'd like to to Marshal to a file, but the default proc prevents me from doing that. Rather than writing my own _dump and _load methods, is it possible instead to remove the default_proc instead? At the point where I'm Marshalling I'm never going to need the default_proc again. ...

Randomizing array elements

hi, i have an array @number = [1,2,3,4,5,6,7,8,9] now, i want to randomize the array content... something like eg: [5,3,2,6,7,1,8] please guide me how to proceed with it. thanks ...

ruby difference engine

Looking for a Ruby differencing engine. So you can do some of the same things meld viewer does. For example you have this first set of code per line: String1 String2 String3 2nd set: String1 String3 String4 The diff would come out to show lines 2 and 3 are different. I already am using this one: http://github.com/pvande/differ...

Is it possible to use KDevelop to debug ruby applications?

Hello. I has read that KDevelop has integrated Ruby support and was interested to test it. But unfortunately, it wasn't easy. First, i was not able to install KDevelop both in Ubuntu and Kubuntu - it's not in the packages, so apt-get install kdevelop does nothing. After enabling unsupported backports, i was able to install KDevelop and ...

Evaluate whether date is not one of past dates in model -- Ruby on Rails

I have a Day model which has a date column. I have to implement the validation that the date column must not have a past date. If the date is a past date it must not get saved to the database and give the appropriate error message right on the. I know I can put this validation in the controller, but I think it violates the MVC rules i.e ...

Ruby on Rails: How do you convert a database entry with attributes inside into a human-readable format?

I'm using the acts_as_auditable plugin, and the revisions attribute gives me this chunk of text (i.e. in the "revisions" column; i.e. @audit.revisions) --- user_id: 2 kind: French name: Delicious Pies I'm trying to convert that text into a human-readable format to display the details of the audit. For instance, I want to convert the ...

Is everything in Ruby can be used in Rails?

It might be a silly question, but seriously is everything in Ruby works in Rails? I mean is that rails did not overwrite anything, but just added new things to ruby, right? (Sorry for the silly question. I just learnt rails for about 4 months and no any experience in ruby yet (except rails ;D)). ...

How can I use "nu install ..." to install nhibernate 3 alpha?

Hi all, I've started using nu and I'm really starting to like the way it managed packages for .net libraries. On this page: http://nu.wikispot.org/Current_Packages it says that you can install the nhibernate alpha version with nu, however I can't for the life of me figure out how. Can anyone help me with the command I would need? Tha...

Business date/holiday handling

I've posted this question for C# but I may be working in Ruby instead. So I'm asking the same question about Ruby: I'm looking for a Ruby class/library/module that works similarly to the Perl module Date::Manip as far as business/holiday dates. Using that module in Perl, I can pass it a date and find out whether it's a business day (i...

What does the "!!" symbol mean in Ruby?

def test !!session[:test] end !! - what does this do? can we remove it and still assume it will work the same? ...

are you allowed to redefine a class in ruby? or is this just in irb

I fired up irb, and typed: class Point end and then I typed that again, but added some other things. Irb didn't complain that I was defining a class that already exists. ...

Are array parameters in rails guaranteed to be in the order in which they appear in the url?

Given the following url: http://example.com?arr[]=hello&arr[]=to&arr[]=you Am I able to bank on the fact that: params[:arr] == ['hello', 'to', 'you'] ? I ask because I have some additional data that will be sent with the request that needs to be mapped to each of the values in params[:arr]. ...

Rails app with nested resources, need help with SearchLogic

I am trying to setup searchlogic on nested resources. I have Category has_many :products also Category has_many :brands through :products So structurally its Category/Brand/Product As a user navigates the site they click a category, which uses the Category#show action. #Category_controller def show @category = Category.find_by_u...

Using Curl to download files that require logging in

I need to download movie files from a website that requires logging in. I started prototyping a script using Mechanize, but I'm wondering if Curl supports sending username and password to the server, which would make my work a lot faster. ...

Iterate hash for specific range ..

How to pass range in hash to iterate from index 1 to last? h = {} h[1..-1].each_pair do |key,value| puts "#{key} = #{value} end This code returning error. how may i pass range in hash ?? EDIT: I want to print first key and value without any calculations. From second key and value i want to do some calculation on my hash. For th...

Ruby: Convert time to seconds?

How can I convert a time like 10:30 to seconds? Is there some sort of built in Ruby function to handle that? Basically trying to figure out the number of seconds from midnight (00:00) to a specific time in the day (such as 10:30, or 18:45). ...

Using a rake task that accepts parameters as a prerequisite

According to http://rake.rubyforge.org/files/doc/rakefile_rdoc.html, you can create a task that accepts parameters and also has prerequisites: task :name, [:first_name, :last_name] => [:pre_name] do |t, args| But what if :pre_name is a task that also accepts parameters? What is the syntax for passing parameters to :pre_name when it is...