ruby-on-rails

Rails ActiveRecord Update question

I have a user model which has multiple addresses. Now for my application in rails, address is not mandatory. So, if someone wants to create a user and enter the address after the user has been created, my application should allow that. My problem is, for Address model I have validations for Address Line 1, City and Postal Code. These fie...

Anyone Try Running Rails 2.2 (or Edge) under Ruby 1.9.1 RC1

Ruby 1.9.1 RC1 was released today so I quickly moved to install it (a test version of course using a suffix of 19). I install Rails and Rack for the 1.9 RubyGems and then create a new Rails site using edge... when I execute: ruby19 ./script/server I watch as the processor usage goes up to 99.8 and the terminal just sits there. Trying ...

ActiveRecord has_n association

I was wondering what the best way to model a relationship where an object is associated with exactly n objects of another class. I want to extend the has_one relationship to a specific value of n. For example, a TopFiveMoviesList would belong to user and have exactly five movies. I would imagine that the underlying sql table would have...

Django, Rails Routing...Point?

I'm a student of web development (and college), so my apologies if this comes off sounding naive and offensive, I certainly don't mean it that way. My experience has been with PHP and with a smallish project on the horizon (a glorified shift calendar) I hoped to learn one of the higher level frameworks to ease the code burden. So far, I...

Anyone developed an App with a Flex UI and Rails backend?

Hi guys, i am looking into the possibilities of doing some work for a client on Flex with a Rails backend. It ain't rocket science however i was wondering if anyone out there had some experiences with these two AWESOME technologies? Thanks in advance.... ...

undefined method 'cache_sweeper'

I'm trying to setup some caching on my site and am having troubles with getting a cache sweeper working. I followed the Railscast but when I try to load a page with the model, I'm getting an error. Here's what I've done thus far: 1.) Added the app/sweepers directory and put a basic sweeper in it: class TeamMemberSweeper < ActionControl...

The differences between .build, .create, and .create! and when should they be used?

So I've been seeing people using .build, .create, and .create! within their controllers more and more lately. What's the difference from just using .new and passig the param'd object and then .save? Are there pros and cons? Does using these other methods offer benefits? ...

how to find items that aren't part of the alphabet

In my view I have an alphabet based selector, to select manufacturers by the first letter of their name. I got that part working. But I have manufacturers whose name starts with a number, for example 3M, or 3DLabs. In the view I have the character "#" to group all those. What should my query/find method look like to retrieve all names th...

Good Ruby/Rails testing tutorial?

Can someone recommend a good, up-to-date tutorial for a complete beginner on one of the major testing frameworks for Ruby, such as Rspec or Shoulda? I'd like to find something that doesn't assume any knowledge about the framework or about testing in general. For example, if the tutorial explained the distinction between TDD and BDD, that...

How to organize Rails models that are too fat?

It is good practice to shift logic from the controller into the model. But in any complex system, this invariably leads to a very large file even if a majority of the methods are one liners as per the Rails Way. I've resorted to splitting up models into other modules and including them in the original model, for example, model_flags, mo...

Stupefied by RSpec

I'm sorry, but this is beginning to feel like kicking myself in the head. I'm completely baffled by RSpec. Have watched video after video, read tutorial after tutorial, and still I'm just stuck on square one. === here is what I'm working with http://github.com/fudgestudios/bort/tree/master === Errors F 1) NoMethodError in 'biddin...

What is your convention for specifying complex SQL queries in Rails?

I am fairly new to Rails and I was curious as to some of the conventions experts are using when they need to construct a very complex SQL query that contains many conditions. Specifically, keeping the code readable and maintainable. There are a couple of ways I can think of: Single line, in the call to find(): @pitchers = Pitcher.fin...

web framework(s) memory footprint

Hypothetically, if I were to build the same app using a few popular/similar frameworks, say PHP(cakePHP|Zend), Django, and Rails, should the memory consumption of each be roughly the same? Also, I'm sure many have evaluated or used each and would be interested in which you settled on and why? ...

Why does Ruby have Rails while Python has no central framework?

This is a(n) historical question, not a comparison-between-languages question: This article from 2005 talks about the lack of a single, central framework for Python. For Ruby, this framework is clearly Rails. Why, historically speaking, did this happen for Ruby but not for Python? (or did it happen, and that framework is Django?) Also,...

Do you have to mess with Rails's "routes.rb" file?

I never touch routes.rb beyond calling map.root to set a default route. I've always been content to use URLs of the form... /controller/action/perhaps_an_id and it works fine. Does this make me a bad person? Am I missing out on something totally awesome? What if I try to adopt RESTful design? Would that mean I have to edit routes.rb...

Refactoring before_filters in Controller

I'm working on a rails app that has a whole bunch of before filters in the users_controller which look up user's stateful roles provided by Acts as State Machine. They look something like this: class UsersController < ApplicationController before_filter :not_logged_in_required, :only => [:new, :create] before_filter :find_user_or_curre...

the example uses RoR ajax protoype helpers - How to do this in JQuery instead?

This page show how to do depended drop-downs using RoR+Prototype. Wonder if somebody would show how to do in JQuery insteaad http://pullmonkey.com/2008/3/30/dynamic-select-boxes-ruby-on-rails ...

Eclipse users: Do you use Aptana too?

This San Mateo development company makes a freely downloadable convenient packaging of many plugins for Eclipse called Aptana. I was recently in an environment where Aptana came pre-installed. Not only is it a good IDE for RoR, it also does a somewhat decent job (sans debugging) for PHP, Python, HTML, CSS, and Javascript. According to th...

Figuring out what Ruby on Rails is...

Is RoR to Ruby equivalent to what the .NET framework is to VB.NET? ...

Rails has_many :through Find by Extra Attributes in Join Model

New to both Ruby and Rails but I'm book educated by now (which apparently means nothing, haha). I've got two models, Event and User joined through a table EventUser class User < ActiveRecord::Base has_many :event_users has_many :events, :through => :event_users end class EventUser < ActiveRecord::Base belongs_to :event belongs...