ruby-on-rails

How do I disable rescue handlers in Ruby on Rails apps when I'm running functional tests?

I have a number of controllers in my Ruby on Rails apps with a rescue handler at the end of the action that basically catches any unhandled errors and returns some kind of "user friendly" error. However, when I'm doing rake test I'd like to have those default rescue handlers disabled so I can see the full error & stack trace. Is there an...

Attaching onClick event to Rails's link_to_function

How do I attach an onclick event to a link_to_function such that clicking on the event refreshes an element on the page (using partials)? When the user clicks the generated link, I'd like to refresh the partial containing the code so that i gets updated. def add_step_link(form_builder) logger.info 'ADD_STEP_LINK' link_to_func...

Generating graphs in a RubyOnRails application

I am wondering what other people have found to be the best graphing libraries/plug-ins/gems etc for a rails app. When I say best, I guess I mean ease of implementation and the ability to customize the graphs. I have previously used openflashchart2 and loved the overall look/effects it has, although customizing everything as required ...

ActiveRecord: deleting associated records

Something I'm not getting... I have this in my model: class Model < ActiveRecord::Base has_many :model_options # a link table for many to many has_many :options, :through => :model_options, :dependent => :destroy, :foreign_key => 'model_id' end And I try to do this: model = Model.fin...

What's a good design for an intermediate triple-relation model?

Hello, I'm new to Rails and don't grasp yet all the possibilities with associations. Here's my problem: I have a couple of models like apple and lemon. Then there's the model 'relation' that holds triples of relations: subject | relation | object apple | is sweeter than | lemon The migration for 'relations' is this: create_table :...

Rails mail tutorial, along with the required settings

I'm new to RoR, writing a simple app. Need to implement mail functionality the usual register/forgot password stuff. I have googled, but haven't got a complete tutorial yet. Most of the tutorials teach how to send mail, but don't help out with the settings. can someone suggest a good tutorial, complete with settings? I'm on ubuntu 9....

Using the same action to show all(index) objects, but also showing a list scoped by a url parameter

I'm having an issue coming up with a good way to do the following. I have a very generic Org model and User model. Org has_many :users, and User belongs_to :org. I am trying to find a way of showing a list of users that is not restricted by Org, but also show a list of User's that is restricted by Org. I know I could nest the routes, an...

Ruby on Rails Question - Answer Website

Does anyone know of a good tutorial or application for asking and answering questions for Ruby on Rails, much like this site (although it probably will be for a very different purpose in the end)? ...

Rails Partial Image Rendering

Hey everyone, I'm getting up to speed on rails and ran into an odd problem. I'm rendering some images from the database (Image models attached to another model, Plants). I'm having some trouble when attempting to do it via a partial. I've got show.html.erb <fieldset class="fieldset"> <legend>Images</legend> <%= unle...

Disable render when testing a controller

Hi, I'm using Test::Unit with shoulda to test a controller. Since I'm just testing the controller I dont wanna the view to be rendered. I'm stubbing some objects, some errors are throw when the view is rendered, but the test shouldn't fail, because the controller is correct. So, theres any way to disable the rendering of a template/v...

Life of variables in Rails

I have the following code: def show @game = $site.new_game_of_type(params[:id]) @game.start end def update_game_time render :partial => 'countdown', :layout => false end and the countdown partial: <div id=countdown> <%= @game.running_time %></div> In show.html.erb I have: Time: <div id="countdown"> </div> <%...

rails activeresource messages

I have a quick question about active resource. If I have a User resource, when I do a call like User.find(1).put(:promote, :position => 'manager') According to the api it translates into this call /users/1/promote.xml?position=manager My question is this. Is activeresource actually making two calls here? find doing a get, then put...

has_one on a belongs_to in Rails?

I am building a rails site and am having trouble with the associations. Basically I have the following: class Publication < ActiveRecord::Base belongs_to :category has_one :site, :through => :category named_scope :on_site, lambda {|s| {:include => [:site], :conditions => ['sites.slug != ?', 's']}} end class Category be...

How to integrate Paperclip and Mimetype-fu

First, a little background, because there is a lot of interaction going on: I'm grabbing emails via Fetcher, and processing them using MMS2R to extract the attachments. These attachments are generally going to be PDF files or MS Word documents, so you'd expect that their content-type would be application/pdf and application/msword respec...

Graph Edges Rails

I found this recently when trying to do bidirectional relationships in rails (http://www.dweebd.com/sql/modeling-bidirectional-graph-edges-in-rails/) class Befriending < ActiveRecord::Base belongs_to :initiator, :class_name => :User belongs_to :recipient, :class_name => :User after_create do |b| BefriendingEdge.create!(:user =...

Use cache money only for a single model?

I want to use cache-money but I don't want to start automatically caching everything (I'm working with a large production app, terabytes of data etc). How do I use it for only the models that I specify? Right now I've got: # initializers/cache_money.rb require 'cache_money' config = (cfg = YAML.load(IO.read(File.join(RAILS_ROOT, "con...

Why does this ActiveRecord method raise a NameError?

Can anyone tell me what's wrong with this code? class Dataset < ActiveRecord::Base has_many :dataitems def self.get_hash(dataset_id) @dataitems = Dataset.find_by_id(24).dataitems @dataitems.each do |di| dataset_hash[di.axis0value] = di.axis1value #assign value for each category value end return dataset_hash end When...

ActiveResource error response header doesn't return body

I asked something similar to this before and never got an answer, here's a shortened version I have a User activeresource model. I make a simple call on my client to the service response = User.find(id).put(:activate, :activation_code => activation_code) If there were errors on the service (ie. activation_code didn't match) I return...

Overriding an attribute in Rails and getting at the underlying value.

For the life of me, I can't figure out how to do this. I have a model for which the stored value is a path to a resource on the file system. I'd like the model to write and fetch the resource from the file system, so I naturally want to override the getter and setters to do this. How do I then get at the underlying value that's in the db...

Scaling with a cluster- best strategy

I am thinking about the best strategy to scale with a cluster of servers. I know there is no hard and fast rules, but I am curious what people think about these scenarios: cluster of combination app/db servers that are round robin (with failover) balanced using dnsmadeeasy. the db's are synced using replication. Has the advantage tha...