ruby-on-rails

How do I use an old version of Rails with Aptana RadRails?

I'm new to Rails development, and I'm trying to figure out how to use an older version of Rails with Apatana's RadRails IDE. I'm trying to help out a friend who has a site built on older version than the one that automatically gets downloaded by RadRails, and I'm pretty sure the two versions wouldn't be compatible (the site is using som...

Rails ignoring render and redirect_to

Hi, I've got a really simple rails question here but I can't seem to find the answer anywhere. I guess some of the problems stem from me following a tutorial for Rails 1.2 with Rails 2.1. Anyway.. I'm writing a blog system and I'm implementing the comments bit. I have comments displaying fine once I've created them using script/console...

Using Ruby-based MySQL adaptor when the C MySQL gem is already installed?

Well this is incredibly frustrating. After being nagged by Rails that I need to install the C-based MySQL adaptor, I did so... and then discovered that it won't work with MySQL under version 6. Now 'gem uninstall mysql' results in 'unknown gem mysql'. I just spent half an hour trying to get the thing to install in the first place (...

Indexes for has_many :through

Suppose you have two models, User and City, joined by a third model CityPermission: class CityPermission < ActiveRecord::Base belongs_to :city belongs_to :user end class City < ActiveRecord::Base has_many :city_permissions has_many :users, :through => :city_permissions end class User < ActiveRecord::Base has_many :city_permi...

How much JavaScript do you let Rails generate?

Ruby on Rails has a lot of ways to generate JavaScript. Particularly when it comes to Ajax. Unfortunately, there are a few problems that I often see with the JavaScript that it generates. Rails typically uses inline event handling. <a onclick="somejavascript(); return false;" /> This is generally frowned upon, as it's mixing ...

Automatic method to set the tabindex using form helpers.

Is there an easy way to have the form helpers set the tabindex parameter automatically when using form helpers in Rails? Basically, I don't want to have to manually set the tab index on every form element when building forms (I keep forgetting to update them when I change things). The majority of the forms I write are basically a list ...

How do you make a method apply to a collection of ActiveRecord objects.

Currently, if I want to apply a method to a group of ActiveRecord objects, I have to structure the call like so: messages = Message.find(:all) csv = Message.to_csv(messages) How can I define the method so it's structured like so? messages = Message.find(:all) csv = messages.to_csv This is the current model code: require 'fastercsv...

In Ruby on Rails, how do I make a polymorphic model associate to a namespaced model?

I have the following models. # app/models/domain/domain_object.rb class Domain::DomainObject < ActiveRecord::Base has_many :links_from, :class_name => "Link", :as => :from, :dependent => :destroy end # app/models/link.rb class Link < ActiveRecord::Base belongs_to :from, :polymorphic => true belongs_to :object_value, :polymorphic...

Why is this line breaking Rails with Passenger on DreamHost?

Ok, so I have a Rails app set up on DreamHost and I had it working a while ago and now it's broken. I don't know a lot about deployment environments or anything like that so please forgive my ignorance. Anyway, it looks like the app is crashing at this line in config/environment.rb: require File.join(File.dirname(__FILE__), 'boot') ...

Correct Rails 2.1 way of doing things

Some of the answers to a question I had about redirect_to made me think about some other questions. Basically I'm writing a blog application using Rails 2.1. I've been trying to do most of it myself (as I know a bit of rails), but with reference to tutorials and references on the internet when I need it. I managed to get a simple blog ...

RJS/Javascript conventions in rails

I'm starting to look into the whole world of RJS and Prototype/jQuery in rails and am a little bit confused. There seems to be no clear line of where to use one or the other. Say i wanted one of the "Active, Hot, Week" tabs like the ones here on SO. When pressing one of them i want to remove a css class (like "active-tab") from the one ...

Anyone using RailRoad diagrams generator?

I recently installed RailRoad gem to generate an .svg diagram of my app's models and controllers. The rake task keeps breaking with a similar error: 1.8/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:263:in `load_missing_constant': uninitialized constant I tried the rake task on 2 seperate apps and ...

Reusing the partials multiple times on one page in Ruby on Rails

I have a partial that renders a select box using the following method: <%= collection_select 'type', 'id', @types, "id", "name", {:prompt => true}, {:onchange => remote_function( :loading => "Form.Element.disable('go_button')", :url => '/sfc/criteria/services', :with => "'ty...

Shoulda testing workflow from the trenches

Everyone is talking about TDD (BDD) in Rails (and not just Rails) development world today. It's easy to find plenty of good general information about it, there are quite a few tools you can use for this purpose and there are many (good) examples of how to use them. Now, I'm already on the train. I like the idea (never did TDD before) a...

Sort tag cloud alphabetically in acts_as_taggable_on_steroids

I got the acts_as_taggable_on_steroids plugin to work fine. The tag_cloud method in my view create and formats the cloud properly however the tags are listed in order of 'count desc'. How to I present my tags in the cloud in alphabetical order? ...

Select Box onClick - Rails

Hi, I have a Rails application that in the erb code, I use a select box. What I would like to do is reload the page passing the sort parameter. My controller already handles it, but I don't know how to reload the page with the selected value from my select box. Here is my code: <% @options = {:latest => 'lastest' , :alphabetical => 'alp...

Rails Cookie Setting Problems

I have a Rails app that sets a cookie and does a redirect to another server once the user is logged in. However, the cookie that the Rails app sets isn't seen by the server for some reason. I've tried setting http_only to false but I still can't even see the cookie unless the domain is the same as my Rails app. Here's the code I'm using ...

How do I view the HTTP response to an ActiveResource request?

I am trying to debug an ActiveResource call that is not working. What's the best way to view the HTTP response to the request ActiveResource is making? ...

Rails Testing: Fixtures, Factories, and Magic numbers

I've got an application that needs quite a bit of data (1000s of records) to do appropriate testing. The only way I've found to get a decent set of testable, sensible data is to use a subset of my production DB. I've converted this to YAML fixtures in the normal `test/fixtures' location. This works, but now I have a bunch of seemingly...

How do I log the entire trace back of a Ruby exception using the default Rails logger?

I am working on rails project and I am trying to get exceptions to be logged to the rails log files. I know I can call logger.error $! to get the first line of the exception logged to the file. But, I want to get the entire trace stack logged as well. How do I log the entire trace back of an exception using the default rails logger? ...