This one tripped me up for almost 2 hours.
When using form_for() within a partial, use the variable reference instead of a symbol when specifying the form object. i.e. Use form_for(@user){|user_form|}, instead of form_for(:user){|user_form|}
I was creating a multi-model form with nested attributes using the new Rails 2.3 fields_for semantics, and the nested model field id's didn't have the numbered "*_attributes_0" suffix string. Ruling out syntax errors, I inspected the nested form objects and found that my user_form.object was nil, and thus the form_for method was not assigning the form object. When led me to find that my use of form_for(:user) was broken. form_for(@user) worked perfectly.
My conclusion may be incorrect, but it appears that using a symbolic reference as an object attribute for form_for() within a partial is broken.
The moral of the story is, just use the variable reference.
Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts
Tuesday, April 21, 2009
Saturday, March 28, 2009
Capistrano deploy.rb for Git and Phusion Passenger
Here is my Capsitrano deploy.rb script/recipe for use with Git repos on servers powered by Phusion Passenger (mod_rails).
http://gist.github.com/87207
http://gist.github.com/87207
Saturday, September 27, 2008
Problems with IE7 Sessions Not Saved in Rails or PHP
If you are unlucky, your login routine will work in Firefox, Internet Explorer 6, Safari, Opera, or whatever, but it won't persist in Internet Explorer 7. x
I spent days on this one: Login worked great in Firefox, but in IE7 the same credentials resulted in a page that looked like I never attempted to log in. The logs showed me that the user credentials were accepted and the page redirected as expected, but the subsequent page load was absent any sign that I logged in.
Well, check your subdomain. You can't have an underscore in a subdomain. http://support.microsoft.com/kb/909264
In this instance, IE7 is inconsistently supporting standards. The browser will accept a badly formatted domain and show you the page in your browser, but will refuse to set the session cookie. Firefox and Safari are not quite so strict.
I spent days on this one: Login worked great in Firefox, but in IE7 the same credentials resulted in a page that looked like I never attempted to log in. The logs showed me that the user credentials were accepted and the page redirected as expected, but the subsequent page load was absent any sign that I logged in.
Well, check your subdomain. You can't have an underscore in a subdomain. http://support.microsoft.com/kb/909264
In this instance, IE7 is inconsistently supporting standards. The browser will accept a badly formatted domain and show you the page in your browser, but will refuse to set the session cookie. Firefox and Safari are not quite so strict.
Thursday, July 03, 2008
Rails: Get controller route hash from url string
This is somewhat uncommon, but to get the routing hash from a URL string:
ActionController::Routing::Routes.recognize_path('/users/1')
# => {:controller => 'users', :action => 'show', :id => '1' }
ActionController::Routing::Routes.recognize_path('/users/1')
# => {:controller => 'users', :action => 'show', :id => '1' }
Subscribe to:
Posts (Atom)