In rails 3, is it possible to create a form_for that works for both new, update and edit actions?
If yes, how do I do this?
I have a admin section so my urls look like:
/admin/posts/ {new,update, edit}
Just let form_for
handle it:
http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-form_for-label-Resource-oriented+style
controller:
class ControllerName
def new
@post = Post.new
end
def edit
@post = Post.find params[:id]
end
end
view:
<%= form_for [:admin, @post] do |f| %>
<% end %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With