ruby

Using Google Search REST API in Ruby

I'm trying to do a google search using Ruby, and print the 1st 3 results. Could anyone point me to a sample code? I'm unable to find it. ...

Best way to implement Categories and Subcategories with flexible depth in Rails?

Hi. I have a Category and Subcategory models in my project. I would like to have many sub-levels in a flexible way. I thought making a self referential "parent" foreign key but I'm not quite sure how to do it. Any ideas? Thanks! Cat1 Sub1 SubSub1 SubSub2 Sub2 Cat2 Sub1 Cat3 Sub1 Sub2 SubSub1 ...

How to modify restful_authentication plugin setup in Rails ?

Hi. I installed restful_authentication a while ago in my project, everything works fine, except that now we requiere the users to activate their accounts via email. I forgot to include the option "--include-activation" when I ran the generate script, is there a clean way to add it now? Or should I re-install the plugin? If so, how can i...

output folded block of text in yaml using ruby

when I do message.to_yaml I am getting the following output mainText: "<h3 class=\"right_column\">Mark</h3> ... " but I want the output in the following format mainText: | <h3 class="right_column">Mark</h3> ... How do you force ruby to use pipe to fold multiple lines of string. I tried message.to_yaml(:UseFold => tru...

What's the equivalent to "method reference" in Ruby

for instance in python it is possible to assign a method to a variable: class MyClass def myMethod(self): return "Hi" x = MyClass() method = x.myMethod print method() # prints Hi I know this should be possible in Ruby, but I don't know what's the syntax. ...

smarter character replacement using ruby gsub and regexp

Hi guys! I'm trying to create permalink like behavior for some article titles and i don't want to add a new db field for permalink. So i decided to write a helper that will convert my article title from: "O "focoasă" a pornit cruciada, împotriva bărbaţilor zgârciţi" to "o-focoasa-a-pornit-cruciada-impotriva-barbatilor-zgarciti". Wh...

Is there any way to get the date modified from Net::SSH or NET::SFTP commands in ruby?

Hi there, Is there an easy way to get the date modified of a file by using Net::SFTP? It'd be nice to be able to do this: Net::SFTP.start('some_server') do |sftp| sftp.dir.glob('*').each do |file| puts file.mtime end end But that's not possible (to my knowledge). Berns. ...

Ruby on Rails issue..mainly dealing with ruby gems/bundler

I was trying to use rspec and for some reason it wasn't working. I think it lacked some dependencies or something. Everything else in Ruby 1.9 was working perfectly on my laptop though. So I did a ruby gems system update (sudo gem update --system). I then did a gem update (sudo gem update). When I tried to run or create apps in rails I g...

How do I process multipart http responses in Ruby Net:HTTP?

There is so much information out there on how to generate multipart responses or do multipart file uploads. I can't seem to find any information on how to process a multipart http response. Here is some IRB output from a multipart http response I am working with. >> response.http.content_type => "multipart/related" >> response.http.bod...

Disable transactions in ActiveRecord

How do I disable transactions in Rails' ActiveRecord? I have a specific situation where I want them to go away I can't seem to find anything useful out there. Is it even possible? ...

Help with HTTP Intercepting Proxy in Ruby?

I have the beginnings of an HTTP Intercepting Proxy written in Ruby: require 'socket' # Get sockets from stdlib server = TCPServer.open(8080) # Socket to listen on port 8080 loop { # Servers run forever Thread.start(server.accept) do |client| puts "** Got connection!" @output = "" ...

Connect to MySQL in Ruby using NetBeans

I've downloaded the "dbd-mysql-0.4.4.zip" and linked it to my project. While I try to run a demo code from NetBeans the very first line require "dbi" gives me an error. Is there a different way to do it? I also tried jruby setup.rb config --with=dbi,dbd_mysql from the command prompt and it gave me the following error: config: unknow...

how can I capture response from twitter.com? ( ruby + twitter gem)

how can I capture response from twitter.com? To make sure that everything went ok? I am using ruby and ruby twitter gem and the my code is basically like that oauth = Twitter::OAuth.new('consumer token', 'consumer secret') oauth.authorize_from_access('access token', 'access secret') client = Twitter::Base.new(oauth) client.update('Hee...

Ruby on Rails: how to get error messages from a child resource displayed?

I'm having a difficult time understanding how to get Rails to show an explicit error message for a child resource that is failing validation when I render an XML template. Hypothetically, I have the following classes: class School < ActiveRecord::Base has_many :students validates_associated :students def self.add_student(ba...

Unable to have nokogiri obey custom path parameters during install

I am trying to install nokogiri locally on dreamhost using the commands: $ wget ftp://xmlsoft.org/libxml2/libxml2-2.7.6.tar.gz $ wget ftp://xmlsoft.org/libxml2/libxslt-1.1.26.tar.gz $ tar zxvf libxml2-2.7.6.tar.gz $ cd libxml2-2.7.6 $ ./configure --prefix=$HOME/local/ --exec-prefix=$HOME/local $ make && make install $ cd .. $ tar zxvf l...

Render public html for dynamic banners in Rails ?

Hi, I would like to render specific HTML snippets for displaying banners, because each banner has a different nature (some images, some flash, etc). Every banner file is under app/public/banners/. I tried many ways, like: render :file => "/banners/somebanner.html" But it can't locate the file, because Rails looks under app/views. Any ...

scrap data from jsp web with Nokogiri or other ruby tools?

there is a jsp web: http://xbrl.cninfo.com.cn/XBRL/allinfo.jsp?stkid=000002&amp;getyear=2005&amp;nowpage=Info.jsp&amp;reportType=GB0110 can i scrap data from it with Nokogiri or other ruby tools? ...

DRY Ruby Initialization with Hash Argument

I find myself using hash arguments to constructors quite a bit, especially when writing DSLs for configuration or other bits of API that the end user will be exposed to. What I end up doing is something like the following: class Example PROPERTIES = [:name, :age] PROPERTIES.each { |p| attr_reader p } def initialize(args) ...

Beginner to RUBY - require_relative problem

Hi, I'm learning Ruby (using version 1.8.6) on Windows 7. When I try to run the stock_stats.rb program below, I get the following error: C:\Users\Will\Desktop\ruby>ruby stock_stats.rb stock_stats.rb:1: undefined method `require_relative' for main:Object (NoMethodE rror) I have three v.small code files: stock_stats.rb require_relati...

How would you write this C# code (that uses the yield keyword) succinctly in Ruby?

Is there a good way to emulate yield in Ruby? I'm interested in writing similar 'infinite fib sequence' in Ruby. Here is the code: using System; using System.Collections.Generic; using System.Linq; namespace cs2 { class Program { static void Main(string[] args) { var i=Fibs().TakeWhile(x=>x < 1000).Whe...