ruby-on-rails

Raising an ActiveRecord error on RecordNotFound

Is there a way of doing a find_by_x that raises an exception if the record is not found? ...

Understanding Routes in Rails

I actually have two questions. I've read the Rails guide and a couple of other articles, but I haven't been able to translate what I read into working routes. I have an application that allows the uploading of images from several different contexts. I'd like the URI to express the proper context so that the following URIs access the same...

Existing Ruby on Rails Open Source CMS-Like systems

I'm looking to build a new project with Rails and I'm looking for a Ruby on Rails (as I know the framework) CMS or project that does mainly the following (so that I don't have to reinvent the wheel): Giving user the ability to make submissions that include text and links to videos/pictures. Users can vote stories up or down and flag i...

Tutorial On Deploying Rails Apps to the Amazon Cloud?

I'm looking for a solid beginning-to-end type tutorial for deploying a Rails application to the Amazon Cloud. Hopefully such a tutorial would include guidance on how, if at all, S3 should be used as well as managing all your persisted data collected in your database of choice. ...

Many to many relationship with Ruby on Rails

I'm working on my first project with RoR and I need to create many to many relationship between two models but with possibility of ordering objects of first model in association to second model. Let's say that I have two following models - Customer - Route I want assign many Customers to many Routes but with storing order of this assoc...

Ruby Enterprise Edition vs Ruby 1.9

Hi, I'm planning to build a website that will be a simple CMS where users submit and view postings with videos, photos and text. One decision I want to make is choosing between Ruby Enterprise Edition and Ruby 1.9. Think I care about in order: 1- Performance & Scalability 2- Compatibility with existing gems/plugins/open source project...

XML Parsing Error: junk after document element. Rails builder

Hello I am trying to send send an xml Doc from an action The XML is created by the following method def media_xml x = Builder::XmlMarkup.new x.instruct! x.declare! :DOCTYPE, :html, :PUBLIC, "-//W3C//DTD XHTML 1.0 Strict//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" x.options{ x.videos{ for m in self.media x.i...

sprockets: can I have two different javascript files included in two different controllers

I am working on a ruby on rails application. All the controllers have one javascript file. However there is a functionality ( call it business.js) which is needed by two controllers. Now just because two controllers need it , I don't want to put this logic in application.js which will make this logic available to all the controllers. I ...

opening browser bookmarks + ruby on rails

Interesting dilemma here. I need the ability for users to add links from their browser bookmarks to a field in a Rails form. Basically I would like them to click a button, have it open their browser bookmarks, have them click a link, and it will automatically populate the form field with the bookmark url. This is a rails / ruby site, bu...

Apply Rails controller filter to all controllers of a particular namespace?

I have a bunch of controllers in a namespace Foo. I'd like to apply a before_filter 'require_user' to all of them, but not to other controllers, that do not belong to Foo namespace. Is there any way to accomplish this besides explicitly invoking a before_filter method in each controller? ...

Rails I18n in verification.rb verify method does not work?

Hi, I am using I18n internationnalization plugin, but it's not translating 1 piece of information : In one of my controller, I have a verify method like this : # Verify user is authenticated verify :only => [ :destroy, :create, :update, :new, :comment ], :session => :user_id, :add_flash => { :error => I18n.t(:'Exceptions....

Hosting Help- Custom Gems on DreamHost

I am attempting to deploy a RoR app using Passenger onto my DreamHost hosting account, but am having trouble getting it up and running. My application requires two custom gems 'amazon-ecs' and 'nokogiri.' As per the instructions on the DreamHost wiki (http://wiki.dreamhost.com/Freezing%5FGems) I froze the gems to vendors by coding them ...

rails decimal precision and scale

I have about 30 tables in a rails app and there are about 6 tables for which I would like to change the precision and scale of some of the decimal columns. How do you go about doing that for already existing columns? Do you need to do each new migration separately, or can they all be done at once. ...

How to make fixtures updateable in Rails' tests?

Below I listed some code from simple Rails application. The test listed below fails in last line, because the updated_at field of the post is not changed within the update action of PostController in this test. Why? This behaviour seems to me a little strange, because standard timestamps are included in Post model, live testing on local...

How to break out from a ruby block?

class Bar def do_things Foo.some_method(x) do |x| y = x.do_somethign return y_is_bad if y.bad? # how do i tell it to stop and return do_things? y.do_something_else end keep_doing_more_things end end here is Foo#some_method. class Foo def self.some_method(targets, &bloc...

How can I make a cascade deletion in a one_to_many relatonship in Rails ActiveRecord?

I have a model in rails with one_to_many relationship. When I delete the father, I'd like to delete all childrens. How should I do it? I want to delete all orders and its items when I delete a user My models are: class User < ActiveRecord::Base has_many :orders, :foreign_key => "id_user" end class Order < ActiveRecord::Base has_ma...

Sort an array in Ruby ignoring articles ("the", "a", "an")

In my application I need to show a list of songs. Right now I'm doing this: Song.all.sort {|x,y| x.artist.name <=> y.artist.name } Unfortunately, this means that "The Notorious B.I.G" will sort with the T's while I want him to sort with the N's (i.e., I want to ignore articles -- "the", "a", and "an" -- for the purposes of sorting. M...

Best way to control shopping carts

Hi I am trying to build a simple shopping cart, i read about controlling them and see there are 3 ways to control them. one is cookies, another one is session based, and last one is database model. I am wondering which one is better choice ? some told that database method is better but its harder too. I am also looking for database model...

How to silence the call to a rails controller's action all together

I've figured out how to silence the contents of an action by wrapping everything inside the action's method in a logger.silence block. However, I still get the call to the action showing up in the log file. I.E: Processing DashboardController#update (for 66.201.17.166 at 2009-09-09 19:03:27) [GET] Parameters: {"todos"=>{"user"=>"25"...

(Rails, Javascript) Handling pop-ups and return values?

Hi All, Quickish issue. I'm currently working with RoR with a great deal of Javascript for a project. I have a particular entity that has a "color" property. Of course I want to do this as "snazzily" (yup that's a word) as possible, however, I'm not sure how to go about it. I've seen a million and one different "Color Pickers" but n...