ruby

incorrect use of ruby's sort_by function

My sort function is clearly not working, I am trying to sort ALL_VIEWS by @permalink.length: ALL_VIEWS.sort_by {|view| view.permalink.length} ALL_VIEWS[0..4].each do |view| puts view.inspect puts view.permalink.length end this produces: #<View:0x1014da7b8 @permalink="xxxx"> 4 #<View:0x1014da790 @permalink="yyyyy"> 5 #<View:0...

401 Unauthorized for foursquare OAuth

OK I am pulling my hair after trying this out too many times to debug. So pls pls help me out here I keep getting 401 Unauthorized error after I am redirected back. Here is my code What am I doing wrong here? require 'rubygems' require 'OAuth' require 'json' class SessionController < ApplicationController before_filter :load_o...

Help with rails json and jquery

Im trying to use this jquery ui widget for autocompleting a textbox in my app. I have created an index.json.erb file inside my views/university folder here's my current (piece of crap) code json='[' <% @universities.each do |u| %> json+='{ "id": "#{@u.name}" , "label":"#{@u.name}" , "value": "#{@u.name}"},' <% end %> json+=']' json N...

Mixed dynamic routes in Rails/Merb

Im trying to figure out the best way to map simple routes into one url. Application contains of 4 models: Location, Category, Budget, Company. But each model could be mapped to single url like this. For real-world example you can check out http://sortfolio.com/ /chicago <- Location /3k-5k <- Budget /bars <- Category /company-name <- Com...

want to modify my update method in Rails, but REST is confining me

The problem: I have a collection of people, I want to have a revise.html page that allows me to increment a integer on all the people. if I make a new method in the people_controller it auto sends me to people/revise.. which gets interpreted as show/revise... which is not an id. I understand this happens because of REST constrictions....

Ruby String parsing like how rails parses routes (with :symbols)

I'm trying to parse out some log files with ruby. I have plenty of experience with regexes but the other day I was using rails routes and thought that might be a really neat way to parse out these log files because it would be incredibly easy to understand the parser. Regex, on the other hand, takes several minutes for most people to d...

Does ruby have something similar to buildout or virtualenv?

I was wondering: In python, canon says to use buildout or virtualenv, to avoid installing into the system packages. It's second nature now, I no longer see anything ludicrously bizarre to the practice. It makes a kind of sense. In Ruby, is there something similar? How does ruby deal with this problem? Does ruby have this problem? ...

Developing financial application

My boss wants me to develop an application very similar to an accounting system (that will be a part of another big system, written in ruby (using rails) and javascript (using extjs)) How can I start? For example, I had a plan to use mongodb for our system, but now I'm not sure because of luck of transactions and ACID in mongodb. Wh...

ImageMagick, passenger, rails, attachement_fu doesn't resize

Hi guys! So after a couple of months of development today I am finaly deploying! (WOOHOO great day). But i am stuck with a problem I can't seem to fix: First of all in development all is working perfectly. In deployment on my server it isn't though!. I use attachment_fu and i am able to upload pictures but the pictures are not resizing...

after_update callback issues

I'm trying to recalculate percentages in an after_update callback of my model. def update_percentages if self.likes_changed? or self.dislikes_changed? total = self.likes + self.dislikes self.likes_percent = (self.likes / total) * 100 self.dislikes_percent = (self.dislikes / total) * 100 self.save end ...

How to use an overridden constant in an inheritanced class

Hey, given this code: class A CONST = 'A' def initialize puts CONST end end class B < A CONST = 'B' end A.new # => 'A' B.new # => 'A' I'd like B to use the CONST = 'B' definition, but I don't know how. Any ideas? Greetings Tom ...

Ruby flow control...

I can't find any useful resources online that breaks down Ruby's different flow-control options. Let's assume that I'm iterating over an array within in a method: def a_method things.each do |t| # control options? end end What are my different flow-control options here? How do they differ? retry return break next redo ...

Executing a mixin method at the end of a class definition

I have a Mix-in that reflects on the receiver class to generate some code. This means that I need to execute the class method at the end of the class definition, like in this trivially dumbed down example: module PrintMethods module ClassMethods def print_methods puts instance_methods end end def self.included(rece...

Communication, Passing Info between PHP App and Ruby App

I primarily work in PHP and prefer to do so since there seem to be more jobs in this language, at least in my area (and I'm still fairly new to it so I want to continue to learn the language better).. but for some things I want to do I need to use the WWW Mechanize library that doesn't work with PHP but does with Ruby (yes I know PHP has...

Defining an array of arrays as a constant

Im trying to define an array of arrays as a Constant in one of my classes, the code looks like this: Constant = [[1,2,3,4], [5,6,7,8]] When I load up the class in irb I get: NoMethodError: undefined method `[]' for nil:NilClass I tried using %w and all that did was turn each one into a string so i got "[1,2,3,4]" inste...

Rspec2: undefined method 'post'

I'm having trouble runnng rspec2 and rails. Here's my log: 1) TrackController home path should be /track Failure/Error: Unable to find C to read failed line undefined method `route_for' for #<#<Class:01x5ffe7c2f>:0x77d36efb> # ./spec/controllers/track_controller_spec.rb:5 # :1 Here's my spec: describe UsersController,...

Integrating Ruby on Windows WAMP server so I can run Ruby and PHP at same time?

I've been searching on this but haven't found anything decisive so far.. I already have a windows WAMP server up and running and am using it for my PHP apps, I want to be able to run some small ruby scripts (to interact with a library that is not available in PHP), I don't even need Rails at this point, I just want to run ruby scripts an...

Bundler not working: in `[]': undefined method `[]' for false:FalseClass

Hi, I'm having some troubles with my Rails app after installing (and removing) Compass. bundle install gives me the following: /Users/[..]/.rvm/gems/ruby-1.9.2-head@rails3beta/gems/bundler 1.0.0.beta.2/lib/bundler/settings.rb:10:in `[]': undefined method `[]' for false:FalseClass (NoMethodError) from /Users/[..]/.rvm/gems/ruby-1.9.2-he...

What is a Good General Purpose Open Source IDE that is written natively for Windows?

Sorry to ask such a general question as I'm sure a lot of questions have been asked before about IDE's... but I specifically have major problems running IDE's that are written in non-native languages for Windows (like Java), NetBeans gave me horrible performance and I just tried Aptana and got a similar issue... I have a fast computer (...

How do I work with checkboxes with DataMapper and Sinatra?

I'm trying to make a simple room management service. The rooms have these properties: class Room include DataMapper::Resource validates_is_unique :number property :id, Serial property :number, Integer property :guest, String property :status, Enum[ :free, :occupied ], :default => :free end Then I create a new room like th...