ruby

How to read JSON from Ruby on Rails with ExtJS

I have some existing projects that were built upon a deprecated PHP framework, and I'm hoping to move them over to Ruby on Rails with minimal effort. My main problem right now is the format that the JSON is coming back in. My frontend code (all ExtJS) is expecting JSON in the format: { "result": [ [id: 1, name: "mike"], ...

Activerecord, select on string compare

Hi all, I have a table called Basic , start_time is one field with type :VARCHAR(5), which actually stores a 5 bytes time data: byte 0 and 1 map to the year , month and day, and byte 2 to 4 map to the hour, min and second. So, it could possible bytes 2 ,3 ,4 are all 0. And I want to do following query : Basic.find (:all , :conditions =...

Rails :overwrite_params with nested parameters

Hi. I'm using the :overwrite_params option in link_to helper. But I have problems overwriting nested parameters values. Here some code: With: link_to book_item.editorial, :overwrite_params => {:filter => {[editorials.id] => book_item.editorial.id.to_s}} The complete params[:filter] value is replaced (ie. I lost params[:filter][:auth...

What is the best payment gateway to use with ActiveMerchant?

I need to set up a payment solution within one of our Rails apps using the ActiveMerchant library. Although this question is highly subjective, what are people experiences with the major gateways out there (BrainTree, Authorize.net etc)? It must: handle recurring payments. have the ability to credit a persons account. have the ability...

Ruby - undefined method `fdiv' for 0:Fixnum

Over the weekend, for some reason, one of our servers has decided to start throwing the following errors (nothing has changed). Any ideas?: /!\ FAILSAFE /!\ 09:57:05 AM Mon, 29 Jun 2009 Status: 500 Internal Server Error undefined method `fdiv' for 0:Fixnum /usr/lib/ruby/1.8/yaml/rubytypes.rb:146:in `is_binary_data?' /usr/l...

Get Facebook UID With Ruby

Hi, I login to the Facebook site, how can I get the UID? Uisng http://mechanize.rubyforge.org/mechanize/ ...

Hpricot Element intersection

Hi, I want to remove all images from a HTML page (actually tinymce user input) which do not meet certain criteria (class = "int" or class = "ext") and I'm struggeling with the correct approach. That's what I'm doing so far: hbody = Hpricot(input) @internal_images = hbody.search("//img[@class='int']") @external_images = hbody.search("//...

How to raise an ActiveRecord::Rollback exception and return a value together?

I have a model that uses a acts_as_nested_set fork, and I've added a method to the model to save the model and move the node into the set in one transaction. This method calls a validation method to make sure the move is valid, which returns true or false. If the validation fails, I want my save method to raise ActiveRecord::Rollback to ...

Can I document Ruby code using Doxygen?

Question: Can I document Ruby code using Doxygen? Disclaimer: I know ruby already has a system for documentation built in and there are probably other ways to do it as well, but the specific constraint I am operating under is how to get Doxygen to do the job (assuming it is possible). Thanks in advance for any pointers. ...

Compiling Ruby 1.9.1 in MinGW

I tried following the README file in Ruby 1.9.1 but I can't compile it using MinGW in Windows. Can you help me with this? Thanks. ...

How do you send raw headers in ruby

I have a page which uses the UTF-8 character set, however the characters are mangled on the page, I think this is just a matter of setting a header "Content-Type: text/html; charset=utf-8" ... I know how to do this in PHP, simply place the following at the top of the page. <?php header("Content-Type: text/html; charset=utf-8"); ?> Is ...

How do I get the second integer in a Ruby string with to_i?

I need to convert some strings, and pull out the two first integers e.g: unkowntext60moreunknowntext25something To: @width = 60 @height = 25 If I do string.to_i, I get the first integer:, 60. I can't figure out how I get the second integer, 25. Any ideas? ...

Login and use rails from C++

I need to use a rails app from C++. I say login in the title because that's one of my options. As far as I see it, I either need to do the standard login, and keep track of a session or something in the C++ code, or use an API token of sorts, and just pass that on every URL and never actually create a session on the rails side (which us...

HTML Agility Pack or HTML Screen Scraping libraries for Java, Ruby, Python?

I found the HTML Agility Pack useful and easy to use for screen scraping web sites. What's the equivalent library for HTML screen scraping in Java, Ruby, Python? ...

A regex I have working in Ruby doesn't in PHP; what could the cause be?

I do not know ruby. I am trying to use the following regex that was generated by ruby (namely by http://www.a-k-r.org/abnf/ running on the grammar given rfc1738) in php. It is failing to match in php, but it is successfully matching in ruby. Does anyone see what differences between php's and ruby's handling of regexes that might expla...

Why can't Ruby on Rails find this class?

Okay. So I have three models, a, b and c. a has_one c, b has_many cs, and c belongs_to both a and b. When I reference "cs" in a method of b, it comes out fine. But when I reference "c" in a method of a, it can't find the reference; it says "c" is an 'undefined local variable or method'. I know that c objects are getting created, because ...

Is there a way to output something in a gem?

It seems that print, put, or logger.info doesn't work in an included gem. I was wondering if there was a workaround. Thanks! ...

Ruby unable to use require

Hello, This is a newbie question as I am attempting to learn Ruby by myself, so apologies if it sounds like a silly question! I am reading through the examples of why's (poignant) guide to ruby and am in chapter 4. I typed the code_words Hash into a file called wordlist.rb I opened another file and typed the first line as require 'wo...

Ruby a clever way to execute a function on a condition

Hey, As a bit of a fun project I'm implementing a Beatnik interpreter in Ruby. If you've never heard of Beatnik it's an esoteric programming language in which operations are specified by the "scrabble score" of the words in the source code. Anyway, the implementation requires a different operation to happen for different scrabble score...

What is a Semicoroutine?

I've been studying fibers in Ruby, and the term semicoroutine has come up. What is meant by a semicoroutine? ...