Allow ActionView form_for object to influence its own submit target

26 views
Skip to first unread message

Benji

unread,
Jul 23, 2015, 5:19:05 AM7/23/15
to Ruby on Rails: Core
At the moment if an object is passed to form_for the action and the method to which the form is submitted is hardcoded. It would be awesome to allow an object to determine its own target. The code for this is located in the method `def apply_form_for_options!(record, object, options)` in file `actionview/lib/action_view/helpers/form_helper.rb` . The responsible line is:
```ruby
action, method = object.respond_to?(:persisted?) && object.persisted? ? [:edit, :patch] : [:new, :post]
```

Maybe if the object responds to something like `target_action_and_method` that returns a similar array with the default given above it would be nice.


Thanks!

Benjamin
Reply all
Reply to author
Forward
0 new messages