ruby

how to mimic a curl action with httparty

I have loved using HTTParty in the past, but at the moment I'm coming up against a problem I haven't been able to figure out yet. The API I'm interacting with is successfully contacted like so: curl -X PUT -d 'id=1175600;status=0' http://www.lingq.com/api_v2/ru/lingqs/?apikey=[long-key] All other functions in this API I haven't had t...

Find parents without or with children in polymorphic associations in rails

I have two models: cars and pictures in my RoR project class Car < ActiveRecord::Base has_many :pictures, :as => :imageable, :dependent => :destroy end and class Picture < ActiveRecord::Base belongs_to :imageable, :polymorphic => true, :dependent => :destroy end How I can find all cars only with child pictures? ...

Are there any ways of speeding up rake?

For me, no matter what rake task has been executed, it's at least 20 seconds. The time is too long. My OS: windows xp, rails: 2.3.8, ruby: 1.8.7 UPDATE Are there any ways of speeding up rake? Someone said upgrade to ruby 1.9, but I don't know does it work well with rails 2.3.8? (I see in the rails' website, they recommend ruby 1.8.7...

pattern matching in ruby

cud any body tell me how this expression works output = "#{output.gsub(/grep .*$/,'')}" before that opearation value of ouptput is "df -h | grep /mnt/nand\r\n/dev/mtdblock4 248.5M 130.7M 117.8M 53% /mnt/nand\r\n" but after opeartion it comes "df -h | \n/dev/mtdblock4 248.5M 248.5M 130.7M 117.8M 53% /mnt/n...

resque , redis and rails 2.3.8

Hi anyone can give me idea what i need to install to setup resque and redis on my rails 2.3.8 application. I have installed. gem install redis gem install redis-namespace gem install resque gem install json after that i have tried to run rake task from my application. C:\test>rake redis:install (in C:/cyncabc) rake aborted! Don't ...

I can't install Haml/Sass on Windows using RubyInstaller for Windows.

I never used ruby before, I just wanted to play around with HAML and SASS. I downloaded and installed Ruby's Windows installer (v1.9.1). Then, I clicked ruby.exe (the icon with a black window and a multicolored gem in the picture). Finally, I typed gem install haml and pressed Enter. But nothing happened. Am I doing something wrong? Ref...

What's the equivalent of python's __file__ in ruby?

In python after imports, one can see the file, that has been loaded/where the module comes from. >>> import os >>> os.__file__ '/Users/tm/lib/python2.6/os.pyc' What would be the equivalent in ruby? >> require 'xmlrpc/client' => true >> ... ...

custom email header

hi i want to add a enquiry id number to my emails so that when a user replies i i can automatically attach the email to an enquiry. I am going to put a message with please do not remove this enquiry number when replying but it would be good if i can put a custom header with the enquiry number so the user doesnt see it. Is this possibl...

Confused, are languages like python, ruby single threaded? unlike say java? (for web apps)

I was reading how Clojure is 'cool' because of its syntax + it runs on the JVM so it is multithreaded etc. etc. Are languages like ruby and python single threaded in nature then? (when running as a web app). What are the underlying differences between python/ruby and say java running on tomcat? Doesn't the web server have a pool of th...

Fastest and most efficient way of converting **haml** and **scss** files? (Ruby on Windows)

I'm a ruby/haml/sass-beginner. I just installed ruby and rails for windows, haml, and sass (stand alone and plugin for rails). I know how to convert and haml file into a html file (and vice versa): haml index.haml > output.html and how to convert a scss fiel into a css file (and vice versa): sass --watch style.scss:style.css I sav...

ruby gtk memory leak on image overlays

Okay: I'm on a linux system, so if you are windows I'm sure you can figure out how to do the equivalent of some of the actions I describe below Create 'test.svg' as such: <svg> <circle cx="100" cy="100" r="100"/> </svg> Now create this little ruby script: #!/usr/bin/env ruby require 'gtk2' Gtk::init pixbuf = Gdk::Pixbuf.new "test...

How do I access a param passed as 'action', since Rails uses that name internally?

I'm working on a rails app that integrates with other systems (which can't be changed), and I need to handle the case below: A user is redirected to my app with a URL like: http://myapp.com/index?action=signout The problem is, I can't access this param through params[:action], since Rails uses that to keep track of the current action....

Scraping pages with asynchronous responses with Hpricot

Hi there, I'm trying to scrape a page but the initial response has nothing in the body as the content is pumped in asynchronously, e.g. the results from a search on the apple website: http://www.apple.com/uk/search/?q=searching+for+something&amp;sec=global Any ideas on how I can successfully grab the results from the search with hprico...

Debugging SOAP4R wsdl2ruby

I'm trying to use wsdl2ruby and it's bombing, I want to give API author feedback. They're not Ruby developers, so I want to give more info than just the backtrace. Any advice on how I can determine what in the WSDL is blowing up this command? wsdl2ruby.rb --force --classdef --mapping_registry --client_skelton --driver --module_path In...

resque , redis and rails 2.3.8

I have one model where i am using resque. This is my model. Class Test < ActiveRecord::Base @queue = :default def self.perform(params) puts "Processed a job!" end def self.load_test123(params) Resque.enqueue(DataFile, params) end end is this a proper way ??? ...

Ruby on Rails and Ubuntu: typing just "script/generate ..." instead of "ruby script/generate"

I'm using Ubuntu 10.04. In the terminal, when I go to my app and type (without using the "ruby" in front): script/generate controller recipes I get a "Permission denied" error. When I use this however: ruby script/generate controller recipes everything works as expected. Is there something I have to do to Ubuntu to make the prepend...

Google Base API

Is there a way to retrieve product information using ruby and google base api. I have installed the googlebase gem: gem install googlebase? I created a test script as mentioned in the example at: http://googlebase.rubyforge.org/ require 'rubygems' require 'google/base' Google::Base.establish_connection('username', 'password') respon...

Starting delayed_job at startup with rails.

I want to start script/delayed_job start on my production when i will start my rails server. Is there anyway i can do that? EDIT:: I have added this line to my config/initializers/delayed_job.rb . Delayed::Worker.new.start But my delayed job server is not starting when i am running my rails applicaiton. Is there any other solution...

XML mapping and validation for Rails models

I am implementing an application that manipulate XML documents using Ruby on Rails. I want to have models that encapsulate all the logic and then convert them to corresponding XML document when save. Although I do not need database persistence for my models, I want my models to have validation mechanism like ActiveRecord's. Also, for con...

How to evaluate a date difference in years, months and days (ruby)?

I have to make a simple difference between two dates: Date.parse("2009-06-20") - Date.today This gives me the difference of the dates in days. Anyone know a way to easily convert that to the following format: The event occurred X years, Y months and Z days ago Thank you. ...