This project is archived and is in readonly mode.
Using form_for with ActiveResource broken in edge
Reported by Gaël Deest | March 18th, 2010 @ 06:04 PM
After submitting a patch for ticket #4155 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 ?
Comments and changes to this ticket
-
Gaël Deest March 18th, 2010 @ 08:09 PM
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.
-
Gaël Deest March 18th, 2010 @ 10:33 PM
- Tag changed from activeresource, edge to activeresource, edge, patch
Here is a cumulated patch for this issue and the one raised by ticket #4155.
Please tell me if there is any problem with this patch.
-
Repository March 27th, 2010 @ 08:40 AM
- State changed from new to resolved
(from [753304bd113d7524f6d48d220483a2723c534557]) Makes ActiveResource work with form_for: - Adds a
build' method that can be used instead of
new' to load a new, unsaved resource from the remote site, filled with the correct default values. - Adds apersisted?' method that simply returns the opposite value than the
new?' method. [#4222 state:resolved] [#4155 state:resolved]Signed-off-by: wycats wycats@gmail.com
http://github.com/rails/rails/commit/753304bd113d7524f6d48d220483a2...
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
Attachments
Tags
Referenced by
- 4222 Using form_for with ActiveResource broken in edge (from [753304bd113d7524f6d48d220483a2723c534557]) Makes A...
- 4155 ActiveResource generates an error for a form_for attribute (from [753304bd113d7524f6d48d220483a2723c534557]) Makes A...