ruby

Installing rails-3.0.0.beta4 , and getting the royal (Errno::ENOENT)

First let me explain that I've created a million lib directories scouring out all the different responses to this same problem but none of them have really done the trick.. I've tried sudo mkdir /opt/local/lib/ruby1.9/gems/1.9.1/gems/rails-3.0.0.beta4/lib sudo mkdir /opt/local/lib/ruby1.9/gems/1.9/gems/rails-3.0.0.beta4/lib sudo mkdir ...

Meta-programming: output method body as text

I'm dynamically defining a method in a module, and I'd like to check that once the method is bound to a class instance that the body of the method is what I'm expecting. Is there a way to output (as text) of the body of a method? Module controller_mixins.rb: module ControllerMixin instance_eval "def search_by_vendor (*args) \n" \ ...

Updating from Ruby 1.8.7 to Ruby 1.9.1

Currently I have Ruby 1.8.7 and Rails 2.3.8. Is it possible to update ruby so that I do not have to re-install all the gems again? ...

Rails Automatic Cache Expiration

Does Rails do any kind of automatic (time-based?) caching expiration for pages/actions/fragments? This seems like such a simple question, yet I can't find it anywhere (or maybe I'm looking in the wrong place). ...

Beginner syntax issues

SO has frozen for the nth time now trying to ask this question, so third time is a charm? I'm trying to write a rubyish solution to problem 6 in Project Euler, because I have the propensity to write C in other languages. However, this code: sqrsum, sumsqr = 0, 0 (1..100).each { |x| sqrsum, sumsqr += x, x**2 } p (sumsqr - (sqrsum ** 2)) ...

Sinatra HTTP 'PUT' method

Something's wrong with the PUT action here, the form gets processed but the updated field is not being saved. I've did what Sinatra users are doing, by adding in "_method" for Sinatra to recognise that's its a HTTP PUT action. Could anyone spot any mistake here? # edit get '/entries/*/:id/edit' do @entry = Entries.get(params[:id]) ...

Rails Caching (content vs. page/action/etc)

What's content caching (like this plugin here: http://blog.codahale.com/2006/04/10/content-only-caching-for-rails/) vs page/action/fragment caching that Rails has built in? I'd like to do caching on my Rails application, but I don't quite know which type to use. My application has mostly dynamic, user specific data on every page. Is cac...

Parse a particular number of lines

I'm trying to read through a file, find a certain pattern and then grabbing a set number of lines of text after the line that contains that pattern. Not really sure how to approach this. ...

Rails AJAX request also calling entire original page

I'm using jQuery getScript in Rails to load an AJAX search on a dashboard page. I just noticed, though, that in addition to properly making the call it's ALSO reloading the entire page (in the background). I have no idea why this happening. I checked all my before_filters, all my authentication logic, I tried using different jQuery a...

Ruby C Extension using Singleton

I only wanted to allow one instance of my C extension class to be made, so I wanted to include the singleton module. void Init_mousetest() { VALUE mouseclass = rb_define_class("MyMouse",rb_cObject); rb_require("singleton"); VALUE singletonmodule = rb_const_get(rb_cObject,rb_intern("Singleton")); rb_include_module(mousecl...

Need to get information from Qt4ruby Form's textedit(textbox) and pass back to string for console.

I think this problem is best described in code. I'm sure the solution is close, I just haven't been able to find it. I've been looking over the Qt4 api as well as doing tutorials. Here is my code so far: require 'Qt4' class PictureCommentForm < Qt::Widget def initialize(parent = nil) super() #setFixedSize(300, 100) @comm...

Rails: Nested Resource Content App Management Structure

I am new to rails, and working on an internal content management app. I have made a prototype, but feel that it is messy and there is a better way. I require the following: My current prototype uses the workflow (http://github.com/geekq/workflow) plugin to manage the state of both the project and topics. I have also looked into acts_as_...

How to test custom rails form builders?

What's the best method to test a custom form builder? Is there a test ActiveRecord class/object in Rails' test suite that i could use, or do i have to create my own mock-class? Which AR behavior do i have to 'emulate'? ...

Using Apache Mahout with Ruby on Rails

I have a ruby on rails application. I have the idea of implementing recommendations in the application. I came to know about Apache Mahout through stackoverflow. Now, If I have to use Mahout, what are the stuff that I have to do. Since it is a Java library, I am not clearly sure how to use it in an Ruby on Rails application. I have a cou...

ruby 1.9 + sinatra incompatible character encodings: ASCII-8BIT and UTF-8

I'm trying to migrate a sinatra application to ruby 1.9 I'm using sinatra 1.0, rack 1.2.0 and erb templates when I start sinatra it works but when I request the web page from the browser I get this error: Encoding::CompatibilityError at / incompatible character encodings: ASCII-8BIT and UTF-8 all .rb files has this header: #!/usr/b...

class declaration for ruby

im new to ruby and rails. in RoR3 a controller inherits from the ActionController::Base request.env["SERVER_ADDR"] so request is a method in Base class (that is inside the ActionController module)? what is env then and ["SERVER_ADDR"]? would be great if someone could make a little code example...that would be very helpful to unders...

Making a calendar with Sinatra

Well I don't actually want to make a calendar but I need a view for each day of the year which I guess is sort of the same. Say I have a view where you see e.g. "July 1st" in the top of the page and you have links to the day before and the day after. Beneath this there is a list of - in my example - rooms and they have different states -...

Automating Windows GUI Testing - FindWindowEx and Control Classes

I've inherited a C# window's application that I'm not real crazy about. I've got a looming deadline and I'm scared to death that some of my changes might be having adverse effects on existing functionality. I've got a hobbyist background to RoR and I'm fairly comfortable with testing in that framework (using both RSpec and Cucumber). ...

How do you upload a file with rest-client and specify the filename?

I tried the following to upload a file with RestClient, but the resulting POST always uses the file's filename ("testfile.txt") instead of "file_name.txt": RestClient::Resource.new(path, resource_options).post(:transfer => { :path => "file_name.txt" }, :upload => File.new('/tmp/testfile.txt', 'rb')) ...

Unexpected '\n' in Ruby Fiber

I'm trying to wrap my head around multithreading, so I'm playing around with Fibers in Ruby. However, when I try to run my script, it tells me I have an unexpected newline character after my ternary statement. Did I miss something about the syntax, here? timer = Fiber.new do |power| power = power.nil? ? 'on' | power start = Time.no...