ruby

What would cause Rails page caching to stop working?

I've got a Rails app that has stopped caching somewhere along the way, and I'm not sure which revision along the way might have stopped it from working. I'm under the impression that page caching, when working properly, should never even hit Rails if it finds the cached file. However, when loading my page and monitoring production.log, ...

Sanity Check with XPath in Ruby Watir

I'm using the Ruby Watir library to do automated testing for a client and I'm having issues with the XPath selector. I think I just need another set of eyes to let me know if I'm just missing something. Here is the selector I'm using: puts ie.cell(:xpath, "//img[@src='3.jpg']/../").text For this set of tables, it works as expected ...

Write binary file in Ruby

Is there a simple way to write binary data into binary file like we used to do in C/C++? For example, how can I create a 4-byte file with serialized 4-byte integer value without using fancy math? ...

Which gems can a Rails app survive without?

actionmailer actionpack activeresource activesupport I have a basic scaffolded CRUD app that uses ActiveRecord to connect to a SQLite database and I have frozen my Rails gems. Which of these gems could I delete without affecting my app? ...

Java's equivalent of Ruby's __FILE__ ?

In Ruby I frequently use File.dirname(__FILE__) to open configuration files and such. For those that don't know Ruby, this will give the location on the file system of the file it's called from. This allows me to package libraries with data and config files and open those files with relative paths. What's the Java equivalent of this? I...

How to make SWF Call a Rails Ajax Request?

Hello, I'm writing an application that requires a flv video to be watched before displaying a proceed button to the next section of the site. Currently when the video ends the SWF player makes a POST request to the server marking the video as watched for the current user. Upon success the SWF player calls a Javascript function... Aler...

How Does One Implement Dynamic 404, 500, etc Error Pages in Rails?

How does one implement dynamic, custom error pages in Rails? For example a custom 404 error page using your application.html.erb layout and some dynamic fields in the page. Also, how does one test this from a local machine? ...

Which PHP Framework is most closely cloned to ActiveRecord (RoR)

As the question says it all. Which framework in PHP is most closely cloned to ActiveRecord (Ruby on Rail). I have gone through many frameworks claiming to be based on ActiveRecord ideology but unfortunately none really come any close to ActiveRecord. Wny? Are there any such frameworks that I have missed? ...

Single Table Inheritance routing?

I have single table inheritance working just fine for my app. I have two user subtypes (Athlete and Company) that inherit the super-type User. Let's say I am listing all users, and want a link to each user's profile from this list. I want to link to the athletes controller if the type is athlete and the companies controller if the type...

How to refactor this Ruby (controller) code?

This is the code in my reports controller, it just looks so bad, can anyone give me some suggestions on how to tidy it up? # app\controller\reports_controller.rb @report_lines = [] @sum_wp, @sum_projcted_wp, @sum_il, @sum_projcted_il, @sum_li,@sum_gross_profit ,@sum_opportunities = [0,0,0,0,0,0,0] date = @start_date num_of_...

STDIN.getc locking my application

I have the following code class TimeReport def run init_screen lines = Curses::lines cols = Curses::cols read="" begin crmode noecho gotoDay diaActual.data.to_s #loads the screen with data while !read.eql?("q") printPrompt #simply prints the command prompt read=STDIN.get...

Where to put these code in a Rails web application?

I have some code that may just need to be called on a lot of places in the controller and model, where do I put these code in ? And how to call those methods then ? Thanks def self.number_of_months(start_date,to_date) # Get how many months you want to view from the start months (to_date.month - start_date.month) + (to_date.year - ...

Rails: has_many :through problem

Hi! I have problems with getting a has_many through association to work. I keep getting this exception: Article.find(1).warehouses.build ActiveRecord::HasManyThroughAssociationNotFoundError: Could not find the association :entries in model Article These are the models involved: class Article < ActiveRecord::Base has...

How to initialize the own class in rails?

I want to call InvoicingAndDelivery.report_lines, then give me an array of those results, but it isn't working. Any ideas? class InvoicingAndDelivery < Report include DateExtentions attr_accessor :report_lines, :tba_line, :sum_line def initialize(part_or_service_ids, start_date, to_date) # @report_lines = [] number_of...

Possible to fetch Rdoc entries from external ruby classes ?

If i have bunch of classes in objectspace and have a list of methods which generated also from objectspace, is there any possibility to fetch rdoc documentation for single method ? Example: FILE: foo.rb # Class rdoc information here class foo # defining bar here, just prints hello world def bar puts "hello world" end end F...

What does middleware mean for Twitter and Scala?

Reference another SO question I had, I was given this article about Twitter moving from Rails to Scala, and in the article is this comment: By the end of this year, Payne said, Twitter hopes to have its entire middleware infrastructure and its APIs ported to the new language. Ruby will remain, but only on the front end. "We...

Does Scala scale better then other JVM languages?

Here is the only way I know to ask it at the moment. As Understand it Scala uses the Java Virtual Machine. I thought Jruby did also. Twitter switched its middleware to Scala. Could they have done the same thing and used Jruby? Could they have started with Jruby to start with and not had their scaling problems that caused them to mo...

Getting started with tests in Rails

We have chosen to use rails to build a small project of ours. This is a really small project and will likely take six man-months or less. All people working on the project are new to Rails and have limited amount of experience in web coding. Our software is supposed to give users an easy-to-use interface to browse vast quantities of mea...

rails: accessing an instance variable in a js.erb file

I am trying to access an instance variable from a js.erb file. #controller def get_person @person = Person.find(1) respond_to do |format| format.js{} end end #get_person.js.erb alert('<%= @person.last_name %>') When I browse to [controller_name_here]/get_person.js ... I get a nil object error on @person. (I know Person.find...

Detect key press (non-blocking) w/o getc/gets in Ruby

I have a simple task that needs to wait for something to change on the filesystem (it's essentially a compiler for prototypes). So I've a simple infinite loop with a 5 second sleep after the check for changed files. loop do # if files changed # process files # and puts result sleep 5 end Instead of the Ctrl+C salute, I'd ...