ruby-on-rails

How do I catch redirections to other domains when testing with Webrat?

In my Rails app, I have a form which redirects through a foreign service, Amazon FPS. The form POSTs to an action in my app which redirects to Amazon, who collect information and then redirect back to my app. I'm testing this workflow with Webrat. Obviously I can't test Amazon, so I want to check that the redirection to Amazon happens...

How do I fake OpenID login in RSpec user story/Cucumber when using open_id_authentication plugin

I'm trying to write a Cucumber scenario that requires me to have a logged in user - that would normally be quite simple but I'm only using OpenID authentication (curtosy of the authentication plugin). However after digging through the open_id_authentication plugins guts I'm not sure how I could achieve this within Cucumber. ...

Rails Schema creation problem

I am using Jruby and rails 2.2.2. My problem is I have a migration that is not being correctly written to the database schema. Here is my migration: class CreateNotes < ActiveRecord::Migration def self.up create_table(:notes, :options => 'ENGINE=MyISAM') do |t| t.string :title t.text :body t.timestamps e...

Url for cities/regions/countries in Rails

What do you recommend for displaying URLs and handling views in Rails for cities, regions, countries? i.e: /us/ca/San-Fransisco /countries/us/regions/ca/cities/San-Fransisco Should be able to: List all countries, list all regions within country and list all cities within a region and country. Where would you put code for displaying ...

Apache giving a 400 Error on a FastCGI VirtualHost

Apache is spitting out a HTTP response of code: 400 "Bad Request" with no details whenever I access a page driven that is handled by a FastCGI script. I've installed the mod_fcgid module and it's loaded and configured in the Apache config files I've tested several FastCGI scripts, all of them run when directly executed. Static resource...

Overriding Rails to_param ??

How do I get the to_param method to deliver keyword slugs all the time? I have trouble getting it to work with this route: map.pike '/auction/:auction_id/item/:id', :controller => 'items', :action => 'show' Earlier the overridden to_param was working for 'items/1-cashmere-scarf' but fails with 'auction/123/item/1' Update: I'm not ...

What is the best way to determine which source files are no longer needed?

I am now responsible for a Rails application that was built in a very quick-and-dirty fashion. It has many view files (html templates) that are not used. It also has many css files that are not used. What is the best way to determine which files are no longer needed so they can be deleted? I'm looking for a generic solution and not a R...

[Rails] Best practice for converting integer value column to string representation.

Lets say you have a model like the following: class Stock < ActiveRecord::Base # Positions BUY = 1 SELL = 2 end And in that class as an attribute of type integer called 'position' that can hold any of the above values. What is the Rails best practice for converting those integer values into human readable strings? a) Use a hel...

To use self. or not.. in Rails

I've been coding in Ruby for sometime now, but I don't understand when to use: def self.METHOD_NAME end or just: def METHOD_NAME end In any Rails model. Is "self" a modifier like private in Java? When should I use it and when not?. Thanks a ton. ...

best way to handle user id hash common to all rails requests

Each client is identified by a hash, passed along with every request to the server. What's the best way to handle tracking a users session in this case? I'm using restful_authentication for user accounts etc. A large percentage of requests are expected to originate without a user account but just the unique hash. My understanding of th...

Getting Started with IronRuby on Rails

Can somebody point me to a tutorial and/or Getting Started document to get IronRuby running Rails? I'm particularly interested in a detailed, step-by-step reference, not general guidelines. ...

What is the correct way to stub template methods on all view specs using rspec-rails?

I have a number of view specs that need certain methods to be stubbed. Here's what I thought would work (in spec_helper.rb): Spec::Runner.configure do |config| config.before(:each, :type => :views) do template.stub!(:request_forgery_protection_token) template.stub!(:form_authenticity_token) end end But when I run any v...

setting new default properties for to_xml serializer in Rails

In Rails, I'm coding a series of controllers to generate XML. Each time I'm passing a number of properties in to to_xml like: to_xml(:skip_types => true, :dasherize => false) Is there a way I can set these as new default properties that will apply whenever to_xml is called in my app so that I don't have to repeat myself? ...

OpenSocial server implementation

What is the preferred method of implementing the OpenSocial platform? I'm aware of Apache Shindig but can't really find any useful information on it. Also, is it possible to use an existing solution like the Rails-based lovdbyless and add OpenSocial features to it? ...

How can I make this Ruby on Rails page more efficient?

I'm building a site where users can track their collection of figures for Dungeons & Dragons (www.ddmdb.com). The models/relationships involved in this funcitonality are the following: User: id login (username) a bunch of other fields Miniature: id name number (# in the set, not count) release_id (foreign key) a bunch of other fi...

Spinning Background Tasks in Rails

What is the preferred way to create a background task for a Rails application? I've heard of Starling/Workling and the good ol' script/runner, but I am curious which is becoming the defacto way to manage this need? Thanks! Clarification: I like the idea of Rake in Background, but the problem is, I need something that is running constan...

are fixtures loaded when using the sql dump to create a test database

Because of some non standard table creation options I am forced to use the sql dump instead of the standard schema.rb (i.e. I have uncommented this line in the environment.rb config.active_record.schema_format = :sql). I have noticed that when I use the sql dump that my fixtures do not seem to be loaded into the database. Some data is l...

Using Erubis 2.6.2 with Rails 2.2.2 is incompatible?

Supposedly installing erubis is as simple as: gem install erubis # And in environment.rb: require 'erubis/helpers/rails_helper' But I haven't found this to be so. Note that there are no evident errors in my code; it runs just fine and dandy with ERB. Where do I put this line? Directly after the boot.rb inclusion it fails to start...

How do I get Hpricot 0.6 Gem Built on FreeBSD?

When I run rake gems:build with hpricot 0.6.164 on my FreeBSD server I get: Error: Failed to build gem native extension. /user/localbin/ruby18 extconf.rb gems:build RB_USER_INSTALL checking for main() in -lc... yes creating Makefile make make install /usr/bin/install -c -o root -g wheel -m 0755 hpricot_scan.so /u...

Javascript Include Tag Best Practice in a Rails Application

Say I need to call a javascript file in the <head> of an ERb template. My instinct is to do the usual: <head> <%= javascript_include_tag :defaults %> <!-- For example --> </head> in my application's layout. The problem of course becoming that these javascript files are loaded into every page in my application, regardless of whether or...