CSC/ECE 517 Spring 2013/ch1a 1b mh: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 4: | Line 4: | ||
==Introduction== | ==Introduction== | ||
==Edit== | |||
<pre> | |||
locate the object | |||
@object = Object.find params(:id) | |||
update it | |||
@object.update_attributes!(params[:param]) | |||
inform of successful update | |||
flash[:notice] | |||
go to the updated object | |||
redirect_to object_path(@object) | |||
</pre> | |||
==Destroy== | |||
<pre> | |||
locate the object | |||
@object = Object.find params(:id) | |||
destroy it | |||
@object.destroy | |||
inform of successful update | |||
flash[:notice] = "Object '#{@object.title}' deleted." | |||
go to the updated object | |||
redirect_to object_path(@object) | |||
</pre> |
Revision as of 21:42, 7 February 2013
Ruby CRUD - Update and Destroy
Introduction
Edit
locate the object @object = Object.find params(:id) update it @object.update_attributes!(params[:param]) inform of successful update flash[:notice] go to the updated object redirect_to object_path(@object)
Destroy
locate the object @object = Object.find params(:id) destroy it @object.destroy inform of successful update flash[:notice] = "Object '#{@object.title}' deleted." go to the updated object redirect_to object_path(@object)