Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

form_for for singular resource will products plural invokes

#267

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

Reported by soliiid · July 17th, 2008 @ 02:01 AM

State: stale
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. josh
    josh
    • State changed from new to stale
    • Tag set to actionpack, helper

    Interesting. Unit tests please.

    July 17th, 2008 @ 02:03 AM

  2. Andrew White
    Andrew White

    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

    July 28th, 2008 @ 12:22 PM

  3. Jérôme
    Jérôme

    Any good news about this error ? :(

    October 4th, 2008 @ 11:04 AM

  4. mike
  5. Adam S
    Adam S

    I would like to see this fixed as well... Workaround here: http://www.expressionlab.com/200...

    January 18th, 2009 @ 01:35 AM

  6. Claudio Poli
    Claudio Poli

    just bashed my head 30 mins on this.

    June 2nd, 2009 @ 10:32 AM

  7. Gravis
    Gravis

    +1 for this bug :)

    the result is pretty unexpected

    September 17th, 2009 @ 11:09 AM

  8. AI
    AI

    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.

    December 9th, 2009 @ 11:13 PM

  9. jd
    jd

    +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... ?

    March 12th, 2010 @ 03:46 AM

  10. Pete
    Pete

    +1...i'm having this issue in rails 2.3.5

    March 14th, 2010 @ 10:37 PM

  11. Brendan Loudermilk
    Brendan Loudermilk

    +1 on this two year-old bug

    June 1st, 2010 @ 10:40 AM

  12. eagle.anton (at gmail)
    eagle.anton (at gmail)
    • Tag changed from actionpack, helper to rails 3 rc, actionpack, helper
    • Importance changed from to

    Confirm bug in Rails 3 RC

    July 29th, 2010 @ 08:19 AM

  13. Ellis Berner
  14. Jake Moffatt
  15. Victor Costan
  16. Eric Hahn
    Eric Hahn

    +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.

    March 24th, 2011 @ 09:39 PM