Topic: Flash Message - Showing the ID

Hello, I am basically trying to figure out how to show a flash message for my system. I have basically got a code in my controller that copies records, this is the code:

def copy
   @artist_to_copy = Artist.find(params[:id])
    @artist = Artist.new(@artist_to_copy.attributes)
      @artist.save
     end

I want a flash message to appear so that everytime I copy a original record it will show on the flash message that it is i.e "This is the copy of 1" and if I copy the record again it will say "This is the copy of 2" etc. I cant seem to figure out how this would work if there are many orginal records like for instance 1, 2, or 3. How would the flash message know that id 4 is a copy of 2 etc. All very confusing but I would be grateful if someone can come up with a solution for me, many thanks

Nish #hmm#

Nish Patel

Re: Flash Message - Showing the ID

You might want to move this message to a different forum since the flash here refers to the program from Adobe I am pretty sure.

But a quick answer to your question would be to use acts_as_tree. This essentially normal table that has an extra column in it called parent. It also adds some default methods to the model to that you can do things like parent.children.length to find the number of children an item has.

In your case you would probably want each copy of an artist to be a child of that original. Then you could artist.children.length to get the number of copies.

Not sure what your objective or reason behind this is, but you may also want to just create references to the original item in a seperate artist_copies table which would save space in the db (since you don't have the same info 100 times) and be more efficient - unless of course you want each record to be able to be modified independently from each other.