ruby

Uploading Pictures Ruby on Rails...

I am new to rails so sorry if this is easy. I am wondering the best way to upload pictures and display them in Ruby on Rails. I have a blog and would like to have the option of attaching a picture when creating a post. ...

Reddit clone in Rails with Rspec, resource_controller problem

http://github.com/samliu/rlinkset ^^ My code so far is pushed to there. Essentially, I'm using resource_controller and I don't really understand resource_controller. When I used scaffolding to create my Post model, I gave it fields like :integer parent #to say what level a post is at (which post ID is this post's parent) :integer user...

(J)Ruby full locales/localisation/cultureInfo support

Hi, Does (J)Ruby support such things like Calendar in Java or CultureInfo in .NET? I want to be able to write code in Ruby similar to this: locale = Locale.new("en-GB") date1 = "30/12/2000".to_date(locale) locale = Locale.new("en-US") date2 = "12/30/2000".to_date(locale) Locale.current = "ru-RU" date2 = "30.12.2000".to_date # uses t...

what does this backtick ruby code mean?

while line = gets next if line =~ /^\s*#/ # skip comments break if line =~ /^END/ # stop at end #substitute stuff in backticks and try again redo if line.gsub!(/`(.*?)`/) { eval($1) } end What I don't understand is this line: line.gsub!(/`(.*?)`/) { eval($1) } What does the gsub! exactly do? the meaning of regex ...

libmysqlclient15-dev on macs?

Does OSX need an install of libmysqlclient15-dev? I'm trying to compile a gem that is failing and a lot of sources says to install "libmysqlclient15-dev" but I only see this for Linux, not OSX. Am I missing something here? ...

Ruby IRC With DCC

I cant seem to figure out DCC using Isaac but I cant seem to figure out how to receive and send files with the bot. I found a different IRC bot here that supports DCC but I cant figure out how to implement it with my app. Can anyone help me? This is the current state of my app: require 'isaac' configure do |c| c.nick = "TheBot...

Ruby system command not working outside console

I am trying to run growlnotify from inside a ruby script. The command I am using is this system("growlnotify Test -m message"). If I use the terminal to execute the script it works fine. If I use Textmate to run the script or Geektool (the eventual target of the script) it does not ever run the growlnotify part. Each other part of the...

Ruby on Rails: Passing argument to singleton

I have a Rails app that repeatedly talks to another Web server through a wrapper, and I'd like to stick the wrapper in a Singleton class so it's not recreated for every request. Easy enough, I thought: class AppWrapper < Wrapper include Singleton end ... wrapper = AppWrapper.instance "url" Only it doesn't work: wrong number of arg...

where is the RubyGems remote server

Actually, not a question but the answer to something I was about to ask because I was only looking at documentation (my mistake) on docs.rubygems.org & google. I found the answer looking at the gem commands. The question was: Where is the remote server that RubyGems uses? Answer - run the command: gem sources -- gives the info ...

ruby hash with self referencing elements / recursive hash

I need a ruby hash H with keys :a, :b, :c so that H[:b] = H[:a] + 1; H[:c] = H[:b] + 2 etc. How can I define such a hash in a one line declaration, like H = {:a=>1, :b => H[:a] + 1, :c => H[:b] +2, ... } ? I need something similar to DataMapper properties declaration: property :path, FilePath property :md5sum, String, :default => ...

sudo rake with parameters

Is: sudo rake install -- --with-mysql-dir=/usr/local/mysql/ a valid terminal command? I try to run this but it doesn't seem to pass in the variable correctly.. However something like this works fine: sudo gem install do_mysql -- --with-mysql-dir=/usr/local/mysql/ ...

Static block in Ruby

Hi. I have been a Java programmer for a while and I am trying to switch to ruby for a while. I was just trying to develop a small test program in ruby and my intention is something like following. I want to create a simple linked list type of an object in ruby; where an instance variable in class points to another instance of same typ...

Is there a way to know the invoking method?

I know the class method tells what is the name of the class of an object, how could I know the name of the invoking method? Is there a way to know that? ...

Ruby for romance? How to update a script from itself.

My wife enjoys it when I use my geek abilities to be "romantic" so I had an idea for a ruby script to install on her Mac that would send her quotes and little notes from me throughout the day. I already figured out that I'll be using GeekTool to run a script in the background and I'll use growlnotify to display the messages. Now what I n...

Best way for smart-paginated-ajax tables in Rails

I'd like to be able to DRY-ly and intelligently set up my Rails controllers so that I can effortlessly use paginated tables of data on various pages. Let me clarify. I already use will_paginate + a custom plugin that I wrote which acts as a table-view creator. This combination works perfectly for "index" actions which simply show one ...

Update a single XML entity using Hpricot in Ruby?

I am going to be using Hpricot to process an XML file. I want to randomly display some quotes from the file, and then I want to keep track of how often each quote has been displayed. Is it possible for me to update a single item within the XML file using Hpricot (or is there some other solution that can do this for me?) or should I just...

How to make Ruby AES-256-CBC and PHP MCRYPT_RIJNDAEL_128 play well together

I'm generating data to send from a Ruby stack to a PHP stack. I'm using the OpenSSL::Cipher library on the Ruby side and the 'mcrypt' library in PHP. When I encrypt using 'aes-256-cbc' (256-bit block size) in Ruby I need to use MCRYPT_RIJNDAEL_128 (128-bit block size) in PHP to decrypt it. I suspect the Ruby code that is broken, becau...

Sinatra - how do I debug it when it's online?

I wrote a teeny tiny Sinatra app that runs fine, locally, but for some reason as soon as I put it online, all I get is 'Internal Server Error'. How do I get the logging output? I'm running on Dreamhost with passenger, using the instructions from the Sinatra book. So I added to more handlers: get '/hello/:name' do "Hello, #{params[:...

Translating algorithm/code from Ruby to PHP

digest = HMAC.digest(Digest.new(SHA1), Base64.decode64(key), HashString) return Base64.encode64(digest.to_s()).chomp() What would the above be in PHP? ...

Reasons for this disparity in execution speed?

I wrote a quick Python script to compare two files, each containing unordered hashes, in order to verify that both files are identical aside from order. Then I rewrote it in Ruby for educational purposes. The Python implementation takes seconds, while the Ruby implementation takes around 4 minutes. I have a feeling this is most likely ...