views:

20

answers:

1

I have a database table with records and I show them on a view page, as below. alt text


my question is: If I click "Destroy" Button the corresponding "quote" should not be deleted from Database but it should be removed from view page for my browser only (using cookies?) (not affected for other computers). How can I implement this ? Thank you.

Destroy view is as below:

<%= link_to "Destroy",quotation_path(p),:method=>:delete  %>

and controller:

def destroy
    @quotation = Quotation.find(params[:id])
    @quotation.destroy

    respond_to do |format|
      format.html { redirect_to(quotations_url) }
      format.xml  { head :ok }
    end
  end  
A: 

Don't use the Destroy method. You're not destroying the record, you're merely hiding it for one user. Presumably, there are other users who still want to see it. Create a separate hide method in the quotation_controller, and map it in routes.rb.

Don't use cookies. The user selections will not persist on different clients. Save hides in the database. Implement a many-to-many association between users and quotations to identify which quotes a user has chosen to hide (or view). The hide method associates (or de-associates) the user with the quotation. You'll also need to modify your index method to remove all the hidden quotes from the view, or do a named_scope in the quotations model to return only unhidden quotes for that user.

Ed Haywood