ruby-on-rails

Printing a file to a printer in Ruby

I need help with sending a formatted text to a printer using Ruby on Ruby on Rails OR sending a pdf file to a printer from Ruby program. I can write the code to create a pdf file from Rails app but don't know how to print that pdf file to a default printer. I am trying to write a small ticketing application with Ruby on Rails. Please he...

How do I add a field in Ruby on Rails?

I'm new to RoR, and I've just used scaffold to generate a table and create the pages for CRUD operations. Now I want to add a new field to this. One place I found tells me how to do that in the database, but is there a way to do it where it will add the field to all the pages too, or is that just a manual operation and I need to make sur...

Oracle problems in Rails with rake, but not with site

Hi guys, I'm working on a Rails site that connects to an Oracle database, and though I didn't build the site from scratch, I'm doing maintenance work. The site uses the delayed_jobs plugin to handle some background tasks and I'd like to be able to run rake jobs:work on the development server to periodically process all jobs in the queu...

How to find if range is contained in an array of ranges?

Example business_hours['monday'] = [800..1200, 1300..1700] business_hours['tuesday'] = [900..1100, 1300..1700] ... I then have a bunch of events which occupy some of these intervals, for example event = { start_at: somedatetime, end_at: somedatetime } Iterating over events from a certain date to a certain date, I create another ar...

Rails / delayed_job - want to load newest version of job class

I'm using the delayed_job plugin in Rails to do background processing, and I'm experiencing a hiccup in the 'agile development' I've been experiencing so far in Rails... Usually in rails if I hit an error / want to add some new functionality - I just add some code and refresh the page and the new code runs. With delayed_job, it seems l...

BDD with Cucumber and MySQL — auto increment issues

I am writing some Cucumber features for my RoR app that insert records into the database then send a query to my XML API. Because of the nature of my requests (hardcoded XML) I need to know what the ID of a row is going to be. Here is my Scenario: Scenario: Client requests call info Given There is a call like: | id | calle...

Variable that's accessible to anything in the controller in Rails

I don't know if this is bad form or not, but I needed to set a file path that's accessible to all objects within actions in my controller. One action in the controller creates a file and stores it in a path. Another action serves the file using send_file. The only place I have been storing variables is along with an object in the model. ...

Rails ActiveRecord w/ MySQL Hangs Once Connection Pool Limit is Reached

Unless specified, ActiveRecord fires up 4 default connections. I've noticed if I reload a simple page, which makes at least one ActiveRecord call, 4 times every thing functions normal. However, on the fifth time, it hangs for almost 5 seconds. So, every 5th page load it hangs for 5 seconds. I upped the default connection pool in my ada...

paperclip + gravatar

Hi all. I've found this tutorial (http://www.coffeepowered.net/2009/02/15/graceful-degredation-using-gravatar-as-a-fallback-avatar-with-paperclip/) about implementing gravatar as default image to the paperclip-enabled model, but on implementing i see message "undefined method `match' for [:format, :png]:Array". Whats wrong in this articl...

Trying to mock "new" through an association

This is in my controller @business = @current_user.businesses.new(params[:business]) @businesses is an array of business objects and I'm unsure of how to mock this cascade of calls. ...

Default Date Format in Rails (Need it to be ddmmyyyy)

Hi There, I've been working with a rails form all day and I was just randomly testing it and tried the date 25/12/2009 and it came up with a huge error. It was at this point I realised that rails is set to american date mode (mm/dd/yyyy) instead of the UK style: dd/mm/yyyy. How can I set rails to automatically deal with all dates in d...

Shutdown hook for Rails

Hi all, I'd like to have some cleanup code run when Rails is shutting down - is that possible? My situation is that I have a few threads in the background (I'm using jruby and calling into java) that live for the life of the process and I need to let them know to shut themselves down Thanks! ...

Modal within a Modal in Ruby on Rails?

I have a Ruby on Rails app with Livepipe widgets - http://livepipe.net/ - and everything has been going great, until the client asked for a modal ontop of another modal. Swapping between modals isn't a problem, but they'd like to see one modal behind the other. I can tell that the tag with the id="control_overlay" is the issue - both ...

Error with Paperclip / FasterCSV Processing for optional csv upload

Hi, I have a page where a user can import data to the site. either in the form of copy and pasting into a text area from excel, or by uploading a .csv file. The controller checks if a csv has been uploaded - if so it processes this, else it will process the pasted content. (working on the assumption the user will only choose one option...

Can Apache BalancerMember be configured to use unix domain sockets?

I am using the Apache Proxy balancer directive to hook up a set of thin servers (for Rails). Like so: <Proxy balancer://thinservers> BalancerMember http://127.0.0.1:5000 route=thin0 BalancerMember http://127.0.0.1:5001 route=thin1 BalancerMember http://127.0.0.1:5002 route=thin2 </Proxy> However, thin can also be conf...

How to manipulate DOM with Ruby on Rails

As the title said, I have some DOM manipulation tasks. For example, I want to: - find all H1 element which have blue color. - find all text which have size 12px. - etc.. How can I do it with Rails? Thank you.. :) Update I have been doing some research about extracting web page content based on this paper-> http://www.springerlink.com...

ruby-on-rails: creating models with single table inheritance?

I have a couple of models in my system: User Reputation Post Reputation Response Reputation (similar to SO). So, they are share some basic code: Incrementing and decrementing values a unique_id belonging to the three object that the reputation represents (User, Post, Response) If there were C++, I would have a superclass ...

No route matches error with application_controller spec

I have an application_controller spec that is failing since I removed the controller/action route from routes.rb. I get the following error: No route matches {:controller=>"application", :action=>"index"} I had many tests fail in the same way, but was able to fix them by including the correct parameters in the get call. So for insta...

How to get ar_fixtures to load protected attributes?

I'm using ar_fixtures to seed data in a rails project (the procedure was written before seed arrived in 2.3.4) It is all working fine, except I find that one column in particular is not getting populated (user_id). user_id is set in the yaml file, for example: - !ruby/object:Service attributes: name: name updated_at: 2009-...

calling custom validation methods in Rails

I just upgraded my rails to 2.3.4 and I noticed this with validations: Lets say I have a simple model Company which has a name. nothing to it. I want to run my own validation: class Company < ActiveRecord::Base validate :something def something false end end saving the model actually works in this case. The same thing h...