Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #10537 (new enhancement)

Opened 2 years ago

Last modified 1 year ago

[PATCH][TINY] ActiveResource in 2.0.1 do not define "new_record?" Fixes form_for issue with ARes

Reported by: cnruby Assigned to: technoweenie
Priority: normal Milestone: 2.x
Component: ActiveResource Version: 2.0.1
Severity: normal Keywords: ActiveResource 2.0.1 method new_record?
Cc:

Description

ActiveResource in 2.0.1 do not define method "new_record?" and update_attributes.

See: http://blog.nicksieger.com/articles/2007/10/06/railsconf-europe-hydra

Attachments

add_new_record_method_to_ares.diff (2.0 kB) - added by EmmanuelOga on 01/17/08 16:19:44.
Patch to add new_record? method as an alias for new? for compatibility with ActiveRecord and (fixes a form_for issue with ARes)

Change History

01/17/08 16:17:47 changed by EmmanuelOga

  • owner changed from core to EmmanuelOga.
  • status changed from new to assigned.

+1

This is important not only for users wanting to replace ActiveRecords with ActiveResources, but also for compatibility with form_for on rails. See, when doing something like:

# new.rhtml <% form_for(@article) do |f| %>

...

form_for method behaves like this:

# action_view/helpers/form_helpers.rb def form_for(record_or_name_or_array, *args, &proc)

... apply_form_for_options!([object], options)

and then:

def apply_form_for_options!(object_or_array, options) #:nodoc:

... if object.respond_to?(:new_record?) && object.new_record?

... assignation of “post” HTTP method to the form

If new_record? is not present on the ActiveResource and it is used with form_for, then the form will be created for an *update* of the resource (i.e. hidden input will be created with value "put") and not for what we need: the creation of the res (method "post", no hidden input).

01/17/08 16:19:44 changed by EmmanuelOga

  • attachment add_new_record_method_to_ares.diff added.

Patch to add new_record? method as an alias for new? for compatibility with ActiveRecord and (fixes a form_for issue with ARes)

01/17/08 16:21:49 changed by EmmanuelOga

  • type changed from defect to enhancement.
  • summary changed from ActiveResource in 2.0.1 do not define "new_record?" to [PATCH][TINY] ActiveResource in 2.0.1 do not define "new_record?" Fixes form_for issue with ARes.

Changed status to reflect the added patch.

01/20/08 23:39:09 changed by nzkoz

  • owner changed from EmmanuelOga to technoweenie.
  • status changed from assigned to new.

PDI?