Greetings,
I''m trying to leverage the "request.post?" information to use
one method
for both insert and update. This Rails Recipes # 33 with a minor twist
to the first line based on another online snippet.
================================ def edit
@company = params[:id] ? Company.find(params[:id]) : Company.new
if request.post?
@company.attributes = params[:company]
redirect_to :controller => "main", :action =>
"home" and return
if @company.save
end
end
================================The above action is called from a button as
follows:
================================
<%= button_to "Add Company", { :controller =>
"company", :action =>
"edit" }%>
================================But when the edit method runs, request.post? is
true and the save method
fires, causing the Company#validates_presence_of code to detect a
missing company name.
Result: The form opens, but it already has an error shown through the
inclusion of an "error_messages_for(:company)" display.
Please help me understand the right way to combine these elements so
that I don''t have to write add and edit methods for every model.
Thanks!
Michael
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---