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
Post a Comment