This project is archived and is in readonly mode.
form_for for singular resource will products plural invokes
Reported by soliiid | July 17th, 2008 @ 02:01 AM
for example:
in routes.rb
map.resource :profile, :controller => 'profile'
in view:
<% form_for(@profile) do |f| %>
...
<%= f.submit "Save" %>
<% end %>
if @profile.new_record? is true, it will raises a NoMethodError exception with the message:
undefined method `profiles_path' for #
if @profile.new_record? is false, the message is
You have a nil object when you didn't expect it! The error occurred while evaluating nil.to_sym
confirmed on
ruby: ruby 1.8.6 (2007-03-13 patchlevel 0) [i686-linux]
rails: freezed revision 9084
and
ruby: ruby 1.8.6 (2007-03-13 patchlevel 0) [i386-mswin32]
rails: rails 2.0.2
Comments and changes to this ticket
-
josh July 17th, 2008 @ 02:03 AM
- State changed from new to stale
- Tag set to actionpack, helper
Interesting. Unit tests please.
-
Andrew White July 28th, 2008 @ 12:22 PM
Looks like there's a couple of problems relating to singular resources here:
1. When the object is a new record the inflection passed to the build_named_route_call in polymorphic_url is :plural instead of :singular
2. The object is passed to the named route call which it isn't expecting resulting in the nil.to_sym exception
The question is how to fix it? A quick workaround is to specify the url in the form_for call e.g:
<% form_for(@profile, :url => profile_path) do |form| %>
A proper fix is a little bit more tricky as polymorphic_url on the face of it can't know whether the object maps to a singular resource or not
-
Adam S January 18th, 2009 @ 01:35 AM
I would like to see this fixed as well... Workaround here: http://www.expressionlab.com/200...
-
AI December 9th, 2009 @ 11:13 PM
I ran into this bug today. The obvious workaround is to define singulars_path as singular_path in SingularsHelper, but a real fix would be nice.
-
jd March 12th, 2010 @ 03:46 AM
+1 :) Hi. Same issue for me using Rails3 beta.
Also, although I'm not sure it would not be a design flaw, one may like to have app/views/resource instead of app/views/resources in the case of a singular resource... ? -
eagle.anton (at gmail) July 29th, 2010 @ 08:19 AM
- Tag changed from actionpack, helper to rails 3 rc, actionpack, helper
- Importance changed from to
Confirm bug in Rails 3 RC
-
Eric Hahn March 24th, 2011 @ 09:39 PM
+1
Two gotchas with singular resources:
1) you have to force the :controller to the singular in the route (or have your singular resource be served by a plural controller)
2) you have to explicitly provide the :url to the singular path in form_for, etc.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Tags
Referenced by
- 3675 form_for doesn't work with new singleton nested resource Isn't this another instance of #267?