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.

Using form_for with ActiveResource broken in edge

#4222

After submitting a patch for ticket #4155 ActiveResource generates an error for a form_for attribute I realized that using form_for with a new instance of ActiveResource has actually been broken in edge since the following change:

https://rails.lighthouseapp.com/projects/8994/changesets/250c809246...

Using form_for on a new ActiveResource now results in the following error:

No route matches {:action=>"destroy", :controller=>"zones", :id=>#<Zone:0x106875828 @attributes={}, @errors=#<OrderedHash {}>, @prefix_options={}>}

Full trace:

On line #4 of /users/gael/code/master/app/views/zones/_form.html.haml

    1: -unless zone.errors.empty?
    2:  .flash.errors
    3:      =error_messages_for(zone)
    4: -form_for zone do |f|
    5:  %p
    6:      =f.label :name, "Zone Name"
    7:      =f.text_field :name

    app/views/zones/_form.html.haml:4:in `_render_template_604396837_2202081640_1390988'
    app/views/zones/new.html.haml:1:in `_render_template_86870869_2202137540_0'
    app/controllers/zones_controller.rb:21:in `new'

Perhaps ActiveResource is not meant to work with RESTful helpers ?

Reported by Gaël Deest · March 18th, 2010 @ 06:04 PM

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

Activity

  1. Gaël Deest
    Gaël Deest

    Adding:

    def persisted?
      return !new?
    end
    

    to activeresource/lib/active_resource/base.rb does the trick. I don't know if it's safe to remove new_record? entirely.

    March 18th, 2010 @ 08:09 PM

  2. Gaël Deest
    Gaël Deest
    • Tag changed from activeresource, edge to activeresource, edge, patch

    Here is a cumulated patch for this issue and the one raised by ticket #4155 ActiveResource generates an error for a form_for attribute.

    Please tell me if there is any problem with this patch.

    March 18th, 2010 @ 10:33 PM

  3. Repository
    Repository
    • State changed from new to resolved

    (from [753304bd113d7524f6d48d220483a2723c534557]) Makes ActiveResource work with form_for: - Adds a build' method that can be used instead ofnew' to load a new, unsaved resource from the remote site, filled with the correct default values. - Adds a persisted?' method that simply returns the opposite value than thenew?' method. [#4222 Using form_for with ActiveResource broken in edge state:resolved] [#4155 ActiveResource generates an error for a form_for attribute state:resolved]

    Signed-off-by: wycats wycats@gmail.com
    http://github.com/rails/rails/commit/753304bd113d7524f6d48d220483a2...

    March 27th, 2010 @ 08:40 AM