ruby-on-rails

Transaction Action with Ruby On Rails

I have a complex action inside controller that performs several update queries to the database. How can I make this action acts like transaction without any structural refactoring? ...

Do you have a Rails development environment running under Windows you're happy with?

Hi, My current Rails development environment is Aptana + RadRails plugin on Windows XP and it's a little slow running tests, rake, and generators. If you've evolved and proven your Windows Ruby on Rails development environment into something you're happy with and is fast, please share the details below. Many thanks, Eliot ...

Is this a legitimate use of Rails' Single Table Inheritance?

I've just been reading Chad Fowler's blog post about 20 Rails Development No-Nos. On Single Table Inheritance he comments: The storage of a column called “type” which holds a class name is a pretty good indicator that something fishy is going on. It’s fishy but not always bad. I think, though, that any time you use it you should ask ...

ActiveScaffold - Specifying Conditions in Embedded Scaffold

Hi, I have a Project model and a TaskType model. Association between the two occurs through a ProjectTaskType model (backed by a link/join table in the DB with foreign keys to both Projects and TaskTypes). A Project has_many TaskTypes :through ProjectTaskType, and a TaskTypes has_many Projects :through ProjectTaskType. I have a...

testing helpers with 'haml_tag'

module FooHelper def foo haml_tag(:div) do haml_content("bar") end end end When I test this I get: NoMethodError: undefined method `haml_tag' This code is perfectly valid and works in a development/production environment. It's something to do with having the haml helpers properly loaded in the test environment. Th...

Multi-stage deployment advice?

What are some best practices and general theory of multi-stage deployment for web apps? I'm particularly interested in deploying Rails apps using Git, Capistrano, and Passenger, and I've found posts that discuss the nuts and bolts of the process: Capistrano: Multistage Introducing AutoTagger What considerations should I take with re...

Continuous Integration Advice?

I'm working on setting up a Continuous Integration server (using Integrity) for my Rails app, and I'd like advice: Do most folks set up CI to build and test their app on every push to their central SCM repository, or only when pushing to their staging branch? I'll use the CI server to automatically run flay, flog, reek, and rcov -- are...

Correctly storing dates with TimeZone in MySQL DB for a Rails application

I'm looking at converting our Rails 2.3 application to correctly handle time zones (at the moment everything is in UTC which isn't right, but is convenient!). I have these settings in environment.rb: config.active_record.default_timezone = :utc config.time_zone = "UTC" Going forward, on each request in our app I plan on making the fo...

Are there any new ruby on rails versus django articles?

I'm trying to decide between the two. I don't know ruby or python very well. I found some articles on SO. Are there any recommended sites? Googling only shows one or two. Thank you. ...

named_scope is creating new objects if I use it with a :join

Disclaimer: My original exposure to Ruby on Rails was literally years ago, and a great many things are new to me now that I'm picking it back up. One of these things is named scopes. They seem great, but I'm not getting the result I expect. Here's a for-instance: class User has_many logs named_scope :logged_in, :joins => ['logs'...

How can I avoid multiple answers by the same user?

I am developing an application based on questions and answers, and I would like to prevent a registered user from posting multiple answers to the same question. How can I do that? And where is the best place to put this code (i.e. controller, model)? ...

Tables representing an enumerated list of codes in Rails?

I've looked through similar questions but I'm still a little perplexed about something that seems to be a simple case in Rails. Let's say I have a model class called Employee. One attribute of an employee is their security_clearance, which is a string that can be None, Some, or Full. No other values are valid. In other applications I'd ...

accepts_nested_attributes_for child association validation failing

Hi all, I'm using accepts_nested_attributes_for in one of my Rails models, and I want to save the children after creating the parent. The form works perfectly, but the validation is failing. For simplicity's sake imagine the following: class Project < ActiveRecord::Base has_many :tasks accepts_nested_attributes_for :tasks end clas...

How to get started with Ruby? How can I use Ruby? What is it famous for? How is a DSL going to be useful?

What are some great Learning resources? What kind of problems do I solve with Ruby? Is learning ruby on rails same as ruby? If my current background is visual studio and microsoft.net framework, is IronRuby the best way for me? Awful lot of questions, please suggest. ...

Rails: How do I save a string representation back into a model?

I have an Employee model that has a SecurityClearanceLevel. When you make a new employee, you're asked to set a SecurityClearanceLevel by choosing from a <select> list. The problem is that when I save the object, it's a string, not a SecurityClearanceLevel, so the save fails. Where do I take care of this kind of back-and-forth conversio...

Model Name Conflict

I have a model by the name Filter but due to the changes in reorganizing the filters from 2.0.3, it is conflicting with the ActionController::Filters::Filter (class) In my filters_controller.rb when I try to find the filter Filter.find(:id) as rails is infering the ActionController::Filters::Filter class rather than my model clas...

apache permissions error

I have an Ubuntu Hardy slice with Passenger Phusion serving up a rails app. I am also using the sphinx full text seach with the thinking_sphinx plugin I can run this command from the terminal: sudo rake ts:index RAILS_ENV=production but if this command is in the capistrano deploy file : run "cd #{current_path}; rake thinking_sphinx:...

Bypassing validation with machinist

Hi, I am writing my specs on my model Thing which has a date field which should be after the date of creation, thus I use the *validate_timeliness* plugin like that validate_date :date, :after Time.now I want to be able to add some Things with an anterior date but validation fails. I want to bypass the validation when creating some T...

RadRails trial expired - any free options for Rails in Eclipse?

I installed RadRails a while back and uninstalled it after it said that my trial had expired. Is it correct that this is the only option for Rails development in Eclipse? And is there any other - free - option for Eclipse? (I tried "Ruby RDT" but it doesn't offer any Rails support, just basic Ruby editing.) ...

Filtering ActiveRecord queries in rails

I'm used to Django where you can run multiple filter methods on querysets, ie Item.all.filter(foo="bar").filter(something="else"). The however this is not so easy to do in Rails. Item.find(:all, :conditions => ["foo = :foo", { :foo = bar }]) returns an array meaning this will not work: Item.find(:all, :conditions => ["foo = :foo", { :...