How do I display the name of a deleted element in Ruby on Rails? -


i have simple rails application create objects (such posts). far can edit , delete them, 1 one, want have <%= notice %> echoing name of deleted object after confirming deletion. possible? if so, how?

this extremely common task in rails, , idiomatic solution forward data deleted record subsequent request via the flash array.

your controller's destroy action should this:

def destroy   @post = post.find(params[:id])   @post.destroy    redirect_to posts_path, notice: "#{@post.name} deleted" end 

in index action, you'll able access flash[:notice] string generated in previous action.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -