[Rails-core] Updating a belongs_to foreign key leaves the old association object available

2006-07-31 Thread Jonathan Viney
Perhaps this is intentional, but it seems unlikely: class Person < ActiveRecord::Base belongs_to :school end p = Person.find(:first) p.school # nil p.school_id = School.find_by_name('High School').id p.school.name # High School p.school_id = School.find_by_name('Primary School').id p.school.nam

Re: [Rails-core] Updating a belongs_to foreign key leaves the old association object available

2006-07-31 Thread Michael Koziarski
p = Person.find(:first) p.school # nil p.school_id = School.find_by_name('High School').id p.school.name # High School You should be assigning .school= here. Why are you working with the id? p.school_id = School.find_by_name('Primary School').id p.school.name # High School <= Shouldn't this b

Re: [Rails-core] Updating a belongs_to foreign key leaves the old association object available

2006-07-31 Thread Jonathan Viney
Isn't the standard way of updating relationships like this to have a select box with name="person[school_id]" which will be updated with update_attributes, like in the second example? I've attached a patch which fixes the behaviour. I guess school_id could access school.id, and school_id= would h

[Rails-core] [PATCH] Long Migration Class Names Raises Error

2006-07-31 Thread Blake Watters
Hello all, I've just generated a migration with a very long and descriptive name, weighing in at 78 characters. Unfortunately this class name causes Rails to generate an exception because it blindly subtracts 75 from the length of the string in the announce method of Migration. This raise

[Rails-core] should filters run more than once?

2006-07-31 Thread Caio Chassot
Right now, filters run for as many times as you call, eg., before_filter. If you do something like: 5.times { before_filter :foo } it might be expect, but I think the more common case of: @ ApplicationController before_filter :foo @ SubController before_filter :foo, :except => :ba

Re: [Rails-core] should filters run more than once?

2006-07-31 Thread Mat Schaffer
On Jul 31, 2006, at 11:17 AM, Caio Chassot wrote: Do you really think it's a good idea to run filters more than once? How about maybe adding a uniq option to pre/append_filter_to_chain, that would ensure a filter is never added twice (but related conditions may be changed)? It would seem t

Re: [Rails-core] should filters run more than once?

2006-07-31 Thread Blake Watters
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 This seems like the reasonable and expected behavior. Many of my filters are reused as part of higher level DSL methods and my app would become unusable if Rails decided to begin ignoring my explicit instructions and refusing to run filters as I

Re: [Rails-core] should filters run more than once?

2006-07-31 Thread Caio Chassot
I don't see the need for a :uniq option, when you can use :only and :except on the before_filter and skip_before_filter flavors... I think of it as way to remove the burden from the programmer to think about whether or not the filter was already present in the inheritance chain or not. Sp

Re: Re: [Rails-core] should filters run more than once?

2006-07-31 Thread David Heinemeier Hansson
> I don't see the need for a :uniq option, when you can use :only > and :except on the before_filter and skip_before_filter flavors... I think of it as way to remove the burden from the programmer to think about whether or not the filter was already present in the inheritance chain or not. Plea

Re: [Rails-core] should filters run more than once?

2006-07-31 Thread Caio Chassot
On 2006-07-31, at 13:48 , David Heinemeier Hansson wrote: Please do come up with some real life examples that skip_* can't deal with. Unless there is a very compelling set of those, I don't think its worth it. I think skip_* can handle it all, I'm just wondering if there are filters running

Re: [Rails-core] should filters run more than once?

2006-07-31 Thread Caio Chassot
and then grep your RAILS_ENV.log for "called repeatedly" So I tested this on an old app of mine and got this: Filter :check_login called repeatedly ... only this one, a on a few certain pages I dug in and it was due to code similar to example I first showed, using: before_filter :foo, :ex

Re: [Rails-core] should filters run more than once?

2006-07-31 Thread Rick Olson
On 7/31/06, Caio Chassot <[EMAIL PROTECTED]> wrote: > and then grep your RAILS_ENV.log for "called repeatedly" So I tested this on an old app of mine and got this: Filter :check_login called repeatedly ... only this one, a on a few certain pages I dug in and it was due to code similar to examp

Re: [Rails-core] should filters run more than once?

2006-07-31 Thread Michael Genereux
I have the opposite. I have authentication levels monitored by before filters from the application level down and refactored them up from gobs of REST controllers. Rick Olson wrote: On 7/31/06, Caio Chassot <[EMAIL PROTECTED]> wrote: > and then grep your RAILS_ENV.log for "called repeatedly"

Re: [Rails-core] should filters run more than once?

2006-07-31 Thread Caio Chassot
On 2006-07-31, at 15:14 , Rick Olson wrote: I rarely put before filters in my application controller, and do very little controller inheritance. I don't see this as an issue at all. I can't say I do either all the time, but I do it enough that I noticed this behavior. But I'm not bringing

[Rails-core] [patch] ruby 1.8.5 warnings

2006-07-31 Thread Courtenay
When running ruby 1.8.5 (latest, stable) a bunch of warnings show up. activerecord/lib/active_record/connection_adapters/oracle_adapter.rb:500: warning: colon will be obsoleted; use semicolon It seems that edge ruby wants this form for case statements: case stuff when 5; something when 6; som

[Rails-core] simply restful has been added to core!

2006-07-31 Thread Rick Olson
Hey guys, David just committed the simply restful plugin to core. Upgrade to edge if you want to try it on your Restified apps and let us know if there are issues. I'm currently seeing one or two edge cases that I'm looking at right now. The API is slightly different now: map.resource :comment

[Rails-core] bug in new map.resources

2006-07-31 Thread Josh Susser
Since trac is still out to lunch... It's great to see SimplyRestful at last being rolled into trunk. The code refactoring looks nice, however there is a bug in handling extra actions in the collection/member/new options. flip_keys_and_values (hash) will lose all but one of the actions that

Re: [Rails-core] bug in new map.resources

2006-07-31 Thread Rick Olson
On 7/31/06, Josh Susser <[EMAIL PROTECTED]> wrote: Since trac is still out to lunch... It's great to see SimplyRestful at last being rolled into trunk. The code refactoring looks nice, however there is a bug in handling extra actions in the collection/member/new options. flip_keys_and_values (

Re: [Rails-core] bug in new map.resources

2006-07-31 Thread Josh Susser
In working out a fix for the flip_keys_and_values bug in map.resources, I got to thinking that the current API for specifying extra actions is backwards. The code doesn't use the un-flipped hash at all, and the flipped version is actually more compact to specify. For example: map.resour

Re: [Rails-core] [patch] ruby 1.8.5 warnings

2006-07-31 Thread Nicholas Seckar
Damn that's ugly. I'd rather stay on 1.8.4...On 7/31/06, Courtenay <[EMAIL PROTECTED]> wrote: When running ruby 1.8.5 (latest, stable) a bunch of warnings show up.activerecord/lib/active_record/connection_adapters/oracle_adapter.rb:500:warning: colon will be obsoleted; use semicolonIt seems that ed

Re: [Rails-core] bug in new map.resources

2006-07-31 Thread Caio Chassot
On 2006-07-31, at 19:07 , Josh Susser wrote: and the flipped version is actually more compact to specify. For example: map.resources :articles, :member => { :get => :reply, :post => [:create_reply, :spawn, :split] } That's what I thought just by lo

Re: [Rails-core] bug in new map.resources

2006-07-31 Thread Josh Susser
Here's a patch that changes map.resources to use the "flipped" hashes for optional actions. Tests pass for new arrangement. Looks like postback actions seem to work again too, though the #filtered_named_routes method in your routing_navigator only shows one of the routes with the same nam

Re: Re: [Rails-core] [patch] ruby 1.8.5 warnings

2006-07-31 Thread Courtenay
Haha.. it kinda makes sense, since the semicolon is breaking a line.. I guess my reason for the patch was that there is inconsistency across rails, with a mix of then, colon, semicolon, and newline.. any thoughts on what it should be? On 7/31/06, Nicholas Seckar <[EMAIL PROTECTED]> wrote: Dam

Re: Re: Re: [Rails-core] [patch] ruby 1.8.5 warnings

2006-07-31 Thread David Heinemeier Hansson
I guess my reason for the patch was that there is inconsistency across rails, with a mix of then, colon, semicolon, and newline.. any thoughts on what it should be? Very much depends on what makes sense in the context. I often use different conditional styles depending on the particulars. Not us

Re: [Rails-core] bug in new map.resources

2006-07-31 Thread Rick Olson
On 7/31/06, Josh Susser <[EMAIL PROTECTED]> wrote: Here's a patch that changes map.resources to use the "flipped" hashes for optional actions. Tests pass for new arrangement. Looks like postback actions seem to work again too, though the #filtered_named_routes method in your routing_navigator o

Re: Re: [Rails-core] bug in new map.resources

2006-07-31 Thread David Heinemeier Hansson
Here's a patch that changes map.resources to use the "flipped" hashes for optional actions. Tests pass for new arrangement. Looks like postback actions seem to work again too, though the #filtered_named_routes method in your routing_navigator only shows one of the routes with the same name (but

Re: [Rails-core] bug in new map.resources

2006-07-31 Thread Rick Olson
> map.resources :comments, :member => { :get => :reply, :post => > [:reply, :spawn, :split] } I totally forgot about this feature: :member => { :reply => :any } Look at line 151 http://dev.rubyonrails.org/browser/trunk/actionpack/lib/action_controller/resources.rb#L151 -- Rick Olson http://t

[Rails-core] Re: ruby 1.8.5 warnings

2006-07-31 Thread Courtenay
ah! but is consistency a strength? On 7/31/06, David Heinemeier Hansson <[EMAIL PROTECTED]> wrote: > I guess my reason for the patch was that there is inconsistency across > rails, with a mix of then, colon, semicolon, and newline.. any > thoughts on what it should be? Very much depends on what

Re: [Rails-core] Re: ruby 1.8.5 warnings

2006-07-31 Thread David Heinemeier Hansson
ah! but is consistency a strength? Context beats consistency every time. But if the context is unimportant, then consistency is preferable to randomness. I'm saying that the context probably did matter in quite a few of the choices. I know I've personally used all the different styles at differ

Re: [Rails-core] bug in new map.resources

2006-07-31 Thread Josh Susser
On Jul 31, 2006, at 8:33 PM, David Heinemeier Hansson wrote: When do you feel that you need postbacks? In some sense, I'm seeing the use of a richer verb set as a way of rescuing us from postbacks. Do you have a few examples in a REST-powered app where they feel like a good fit? I'm starting to

Re: Re: [Rails-core] bug in new map.resources

2006-07-31 Thread David Heinemeier Hansson
Postbacks aside, I still think inverting the optional actions hashes (key by method instead of action) is still a better way to go. It's less to type, less to transform, and I tend to think of the actions grouped by http method anyway (at least when doing restful routes). It's not a huge differen

Re: Re: [Rails-core] Re: ruby 1.8.5 warnings

2006-07-31 Thread Courtenay
> ah! but is consistency a strength? Context beats consistency every time. But if the context is unimportant, then consistency is preferable to randomness. Yeah!! I'm saying that the context probably did matter in quite a few of the choices. I know I've personally used all the different style

Re: [Rails-core] bug in new map.resources

2006-07-31 Thread Josh Susser
On Jul 31, 2006, at 9:41 PM, David Heinemeier Hansson wrote: Postbacks aside, I still think inverting the optional actions hashes (key by method instead of action) is still a better way to go. It's less to type, less to transform, and I tend to think of the actions grouped by http method anyway