ruby

Establishing connection w/ Amazon s3 from Heroku

I am attempting to deploy my first app on Heroku and having a little trouble getting the S3 connection to work. Here is the error I am getting from the Heroku logs: AWS::S3::CurrentBucketNotSpecified (No bucket name can be inferred from your current connection's address (`s3.amazonaws.com')): I have the following configured: config...

How to save posts as a text file

I am developing a mobile Application that users can view their Blog posts and also make posts to their blogs via a mobile phone. I also want it in such a way that the users can save a particular post of interest for future references or to read when they are offline. What I intend doing is to save the post as a text file and save the tit...

Read contents of a local file into a variable in Rails

All I want to do is get all the content from a local file and store it in a variable. How? File.read(@icon.full_filename).each {|l| r += l} only gives me a part of it. In PHP, I just used file_get_contents. Thanks! ...

Restrict a number to upper/lower bounds?

Is there a built-in way or a more elegant way of restricting a number num to upper/lower bounds in Ruby or in Rails? e.g. something like: def number_bounded (num, lower_bound, upper_bound) return lower_bound if num < lower_bound return upper_bound if num > upper_bound num end ...

Continuous build framework for java+python+ruby?

Our technology set includes java, python, and ruby code (no, we're not google ;-) ). Recommendations on good CI framework to use? Hudson? Other? dwh ...

How do I set up my @product=Product.find(params[:id]) to have a product_url?

Trying to recreate { script/generate scaffold }, and I've gotten thru a number of Rails basics. I suspect that I need to configure default product url somewhere. But where do I do this? Setup: Have: def edit { @product=Product.find(params[:id]) } Have edit.html.erb, with an edit form posting to action => :create Have def create { ... ...

how to organize classes in ruby if they are literal subclasses

I know that title didn't make sense, Im sorry! Its hard to word what I am trying to ask. I had trouble googling it for the same reason. So this isn't even Ruby specific, but I am working in ruby and I am new to it, so bear with me. So you have a class that is a document. Inside each document, you have sentences, and each sentence has...

Algorithm to Render a Horizontal Binary-ish Tree in Text/ASCII form

It's a pretty normal binary tree, except for the fact that one of the nodes may be empty. I'd like to find a way to output it in a horizontal way (that is, the root node is on the left and expands to the right). I've had some experience expanding trees vertically (root node at the top, expanding downwards), but I'm not sure where to st...

Running Ruby app on Apache

I have been learning Ruby lately, and I want to upload a test web application to my server. But I can't figure out how to get it to run on my shared hosting. My Hosting Details Shared Hosting with JustHost (see here for list of features) OS: Linux Apache: 2.2.11 cPanel: 11.25.0-STABLE No SSH access. Can install Ruby Gems. Can't instal...

Shared Variable Among Ruby Processes

I have a Ruby program that loads up two very large yaml files, so I can get some speed-up by taking advantage of the multiple cores by forking off some processes. I've tried looking, but I'm having trouble figuring how, or even if, I can share variables in different processes. The following code is what I currently have: @proteins = ""...

Convert SQL query to Ruby help

Hey all, I need to query my database table to find which employee has the most support tickets related to them. I can do this just fine using this MySQL query: SELECT employee_id, COUNT(id) AS number_of_tickets FROM tickets GROUP BY employee_id ORDER BY number_of_tickets DESC LIMIT 1; How would write this in Ruby-on-Rails? Thanks v...

In MongoDB, how can I replicate this simple query using map/reduce in ruby?

Hi, So using the regular MongoDB library in Ruby I have the following query to find average filesize across a set of 5001 documents: avg = 0 total = collection.count() Rails.logger.info "#{total} asset creation stats in the system" collection.find().each {|row| avg += (row["filesize"] * (1/total.to_f)) if row["filesize"]} ...

Metaprogramming ActiveRecord Rails

Hi, I have the following code in my project`s lib directory module Pasta module ClassMethods def self.has_coordinates self.send :include, InstanceMethods end end module InstanceMethods def coordinates [longitude ||= 43.0, latitude ||= 25.0] end end ActiveRecord::Base.extend ClassMethods ...

PUT-ing a form to update a row, but I can't find the id. Where is it?

How should I be passing in the ID? Error: Couldn't find Product without an ID Form: <% form_for :product, @product, :url => { :action => :update } do |f| %> <%= f.error_messages %> <p> <%= f.label :names %><br /> <%= f.text_field :names %> </p> <p> <%= f.submit 'Update' %> </p> <% end %> Controller (for /...

Getting all methods inside a script file

After executing this code: var runtime = IronRuby.Ruby.CreateRuntime(); var engine = IronRuby.Ruby.CreateEngine(); var scrope = engine.CreateScope(); engine.ExecuteFile("libtest.rb"); How can I get all the methods of a ruby class in c# code? ...

In Ruby, how to write a method to display any object's instance variable names and its values

Given any object in Ruby (on Rails), how can I write a method so that it will display that object's instance variable names and its values, like this: @x: 1 @y: 2 @link_to_point: #<Point:0x10031b298 @y=20, @x=38> (Update: inspect will do except for large object it is difficult to break down the variables from the 200 lines of output, ...

reverse a string in ruby

How do you reverse a string in Ruby? I know about string#reverse. I'm interested in understanding how to write it in Ruby from scratch preferably an in-place solution. ...

How does bundler work (in general)?

Hello, I'm pretty new to Ruby/Rails but I was taking a look at bundler and was wondering how it works exactly. Do you install a full set of gems like normal gem install XYZand then use the Gemfile to pull a certain subset of those gems for use with a specific application? Or do you not install gems normally anymore and just include them ...

In which versions of ruby are external iterator speeds improved?

According to this rubyquiz, external iterators used to be slow, but are now faster. Is this an improvement only available in YARV (the C-based implementation of ruby 1.9), or is this also available in the C-based implementation of ruby 1.8.7? Also, does enum_for rely on external iterators? ...

Overriding Ruby's spaceship operator <=>

I am trying to override Ruby's <=> (spaceship) operator to sort apples and oranges so that apples come first sorted by weight, and oranges second, sorted by sweetness. Like so: module Fruity attr_accessor :weight, :sweetness def <=>(other) # use Array#<=> to compare the attributes [self.weight, self.sweetness] <=> [other.we...