ruby

how do we delete sessions in rails?

is there another way to delete sessions variable? i was thinking of sessions = nil ...

Activesupport::JSON.decode crashes on this,

I wonder why i cant decode this json string, all what i want is to convert this to a proper Ruby hash, anyone have an idea? i think the array of objects is cracking it ? Parameters: {"{\"origins\":"=>{"{\"origin\":\"this\"},{\"origin\":\"dont\"},{\"origin\":\"dont me please\"},{\"origin\":\"and me please\"},{\"origin\":\"dont\"},{\...

Creating an Ajax timer in Ruby/Rails?

I'm trying to figure out the best solution to create a "game-round" timer in Ruby/Rails. Right now I'm just jotting notes, but in theory I'd like to set a 30 second timer on each round of game activity. Once the timer hits 0, the users turn is over. On Ruby's end, I know I can accomplish this with a while loop and sleep(30), or some c...

Need help with Sprouts (Ruby + RubyGems + AS3) - can't rake

So I'm trying to use Sprouts for AS3. I've installed Ruby and I've installed RubyGems, and I'm able to create a new project using "sprout -n as3 MyProject" - that builds fine. However, when I enter into that folder and type "rake" it errors out with the message "Could not find RubyGem win32-open3 (= 0.2.5)" I've googled around a little...

In ActiveRecord, how to specify a class attribute that is calculated just once for the duration of the page?

Let's say I have an ActiveRecord called Apples, and I want a class method that calculates the total price of every apple in my database, as so: def Apples.total_price Apples.sum(:price) end This is a method I use in one of my views to make a pie chart. So, something like: Apples.brand("red delicious").sum(:price)/Apples.total_price...

Ruby consume array part by part

Hi, Let's say I've array with n elements. I want to take first ten elements and do something with them and then next ten and so on until array is done. What's the right Ruby way to do it? (With c-language background I could write some for-loop and inside the loop count to ten, do stuff and set my bookkeeping variable to zero and contin...

How do I get the pik gem to play nicely with cygwin in Windows XP? Or is there another way to get multiple versions of ruby up and running easily in cygwin?

Pik looks great if you're stuck on a windows machine. The only problem is it appears to be set up for a windows command prompt, and I'm using cygwin. Whenever I try to switch to a different version of ruby in cygwin, it still just uses the default cygwin installation of ruby. $ pik list 186: ruby 1.8.6 (2009-06-08 patchlevel 369) [i386-m...

How to upload big files to a rails application?

I have a ruby application that's used by users via a rails web app. The use case that i need to solve is: each user needs to compile create an entity on database via the web page and put a really big attachment (can be 100gigs or more too) related to the entity. Now this is too big to be handled by normal upload plugins, i am searching...

jQuery get request against Sinatra does not get text

I have a very simple sinatra site that I'm trying to access via ajax through jQuery. To keep things incredibly simple, this code snippet: get '/behavior_count' do "60" end which returns "60" in the browser, shows up as an empty string when attempting to access the site via $.get in jQuery. The strange part is in Firebug, while the...

Installing gems - what does "INFO: `gem install -y` is now default and will be removed" mean

When I install a new gem, I see this message: "INFO: gem install -y is now default and will be removed" What does it mean? My quick Google search didn't turn up anything useful. ...

Replace urls with the shortened version - Ruby

Replacing the urls in a block of plain text is done by looking for url regular expressions. I am using string.gsub(regex, "\1") to achieve the same. I would like to know how to proceed if the shortened url (using api's of any url shortening service) is to be used as the replacement and not the original url. I am using Ruby. ...

How can I search a Ruby Maglev array of objects?

How can I search a maglev array of objects? Maglev is great but it doesn't seem to have any querying capabilities. Are there any external libraries for this? ...

How can I run Rails on Maglev?

How can I run Rails on Maglev? It seems that it can run Sinatra, but not full blown Rails. ...

How to search emails that are not listed in a given MessageUIds using IMAP?

I'm using http://ruby-doc.org/stdlib/libdoc/net/imap/rdoc/index.html to access gmail. I can search for emails with a particular label, but I'm trying to avoid to search an email twice. So in order to do that, I thought that I could store the message_id of each email so that in the next searches I would reefer to that message_id to avoi...

What does :: mean in Ruby?

What does :: mean in Ruby? I see it used when calling a lot of gems. Example: ActiveRecord::Base.establish_connection(...... ...

How to get ALL of the URL parameters in a Sinatra app

Using the following Sinatra app get '/app' do content_type :json {"params" => params}.to_json end Invoking: /app?param1=one&param2=two&param2=alt Gives the following result: {"params":{"param1":"one","param2":"alt"}} Params has only two keys, param1 & param2. I understand Sinatra is setting params as a hash, but it does not r...

Recursively merge multidimensional arrays, hashes and symbols

I need a chunk of Ruby code to combine an array of contents like such: [{:dim_location=>[{:dim_city=>:dim_state}]}, :dim_marital_status, {:dim_location=>[:dim_zip, :dim_business]}] into: [{:dim_location => [:dim_business, {:dim_city=>:dim_state}, :dim_zip]}, :dim_marital_status] It needs to support an arbitrary level of depth, ...

File paths in Ruby

So I want to make a file path relative to the directory it is in, in Ruby. I have a project, and I want it to be able to find the file no matter what directory the project is unzipped into. (Say the code is run on different machines, for example) I can't figure it out for the life of me. It seems for requires that I can do this: req...

Parsing date from text using Ruby

I'm trying to figure out how to extract dates from unstructured text using Ruby. For example, I'd like to parse the date out of this string "Applications started after 12:00 A.M. Midnight (EST) February 1, 2010 will not be considered." Any suggestions? ...

First Ruby on Rails App: use v3 (Beta) or 2.3?

Now that Rails 3.0 beta has been released, should I spend time building my first Rails application on 2.3 or does it make more sense to use the beta? ...