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# -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
How about something like this? Untested, but uses a self-referential join == controller = def copy artist = Artist.find(params[:id]) copy = artist.copy flash[:message] = "This is the copy of #{@original.copies.size}" redirect .... end == model = class Artist < ActiveRecord::Base has_many :copies, :class_name => ''Artist'', :foreign_key => ''copy_id'' def copy artist = copies.build_copy(attributes) artist.save! artist end end On Nov 24, 7:01 am, Nish Patel <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> 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# > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I have tryed this and get this error message: NameError in ArtistsController#copy undefined local variable or method `artist'' for #<ArtistsController:0x481f0e8> RAILS_ROOT: C:/INSTAN~1/rails_apps/example4/config/.. Application Trace | Framework Trace | Full Trace #{RAILS_ROOT}/app/controllers/artists_controller.rb:25:in `copy'' Request Parameters: {"id"=>"79"} Show session dump --- flash: !map:ActionController::Flash::FlashHash {} Response Headers: {"cookie"=>[], "Cache-Control"=>"no-cache"} -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
If you can paste your controller to http://pastie.caboo.se/ I will take a look. The cause of the error is not jumping out at me. Cheers, Nicholas On Nov 24, 10:51 am, Nish Patel <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I have tryed this and get this error message: > > NameError in ArtistsController#copy > > undefined local variable or method `artist'' for > #<ArtistsController:0x481f0e8> > > RAILS_ROOT: C:/INSTAN~1/rails_apps/example4/config/.. > Application Trace | Framework Trace | Full Trace > > #{RAILS_ROOT}/app/controllers/artists_controller.rb:25:in `copy'' > > Request > > Parameters: {"id"=>"79"} > > Show session dump > > --- > flash: !map:ActionController::Flash::FlashHash {} > > Response > Headers: {"cookie"=>[], "Cache-Control"=>"no-cache"} > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Nicholas Henry wrote:> If you can paste your controller to http://pastie.caboo.se/ I will > take a look. The cause of the error is not jumping out at me. > > Cheers, > Nicholas > > On Nov 24, 10:51 am, Nish Patel <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>Sorry for the late reply had a holiday i have pasted my controller thanks again for your help -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Nicholas Henry wrote:> If you can paste your controller to http://pastie.caboo.se/ I will > take a look. The cause of the error is not jumping out at me. > > Cheers, > Nicholas > > On Nov 24, 10:51 am, Nish Patel <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>Sorry for the late reply had a holiday i have pasted my controller thanks again for your help -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
It helps to provide a link to the code :) It''s ok though I managed to find it. The problem is: def copy @artist = Artist.find(params[:id]) copy = artist.copy flash[:message] = "This is the copy of #{@original.copies.size}" end The line should should be copy = @artist.copy you are missing the instance variable. You could get away with just this as you don''t need instance variables. def copy artist = Artist.find(params[:id]) copy = artist.copy flash[:message] = "This is the copy of #{artist.copies.size}" redirect_to artist_path(copy) # action => ''show'', id => copy.id or maybe redirect back to the original? end Note the correction to the flash message. Also note that you will that you will probably want to do a redirect since this is not an idempotent action. HTH, Nicholas On Nov 27, 4:30 am, Nish Patel <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Nicholas Henry wrote: > > If you can paste your controller tohttp://pastie.caboo.se/I will > > take a look. The cause of the error is not jumping out at me. > > > Cheers, > > Nicholas > > > On Nov 24, 10:51 am, Nish Patel <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > Sorry for the late reply had a holiday i have pasted my controller > thanks again for your help > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I know I am a newbie and always reading these books on Ruby, but I just get frustrated when things dont work, lol I have another error messgae and I am trying to figure out what it is i cant seem to create a copy, I will send it as an attachment so you can look at it better, thanks for you help again. You have been awesome! Attachments: http://www.ruby-forum.com/attachment/1052/example4.rar -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Nish Patel wrote:> I know I am a newbie and always reading these books on Ruby, but I just > get frustrated when things dont work, lol I have another error messgae > and I am trying to figure out what it is i cant seem to create a copy, I > will send it as an attachment so you can look at it better, thanks for > you help again. You have been awesome!the error message is : You have a nil object when you didn''t expect it! The error occurred while evaluating nil.copy RAILS_ROOT: C:/INSTAN~1/rails_apps/example4/config/.. Application Trace | Framework Trace | Full Trace #{RAILS_ROOT}/app/controllers/artists_controller.rb:25:in `copy'' etc -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
The solution I provided yesterday would have fixed this problem :) Here is the fix: http://pastie.caboo.se/123019 On Nov 28, 5:56 am, Nish Patel <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I know I am a newbie and always reading these books on Ruby, but I just > get frustrated when things dont work, lol I have another error messgae > and I am trying to figure out what it is i cant seem to create a copy, I > will send it as an attachment so you can look at it better, thanks for > you help again. You have been awesome! > > Attachments:http://www.ruby-forum.com/attachment/1052/example4.rar > > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Nicholas Henry wrote:> The solution I provided yesterday would have fixed this problem :) > > Here is the fix: > > http://pastie.caboo.se/123019 > > On Nov 28, 5:56 am, Nish Patel <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>many thanks again, this stupid things is never gonna work :( I done what you asked me to do and cmae up with this: NoMethodError in ArtistsController#copy undefined method `build_copy'' for Artist:Class RAILS_ROOT: C:/INSTAN~1/rails_apps/example4/config/.. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Sorry, I gave you the wrong syntax. The code: copies.build_copy(attributes) should be: copies.build(attributes) HTH, Nicholas On Nov 28, 8:00 am, Nish Patel <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Nicholas Henry wrote: > > The solution I provided yesterday would have fixed this problem :) > > > Here is the fix: > > >http://pastie.caboo.se/123019 > > > On Nov 28, 5:56 am, Nish Patel <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > many thanks again, this stupid things is never gonna work :( I done what > you asked me to do and cmae up with this: > > NoMethodError in ArtistsController#copy > > undefined method `build_copy'' for Artist:Class > RAILS_ROOT: C:/INSTAN~1/rails_apps/example4/config/.. > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I see!!! it works now thanks you very much Nicolas the only thing is that the message doesnt show up i dont know why and when i change it to a notice the only thing showing on the page is This is the copy of #{@artist.copies.size} as the message, strange -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Nish: Just change: flash[:notice] = ''This is the copy of #{@artist.copies.size}'' to flash[:notice] = "This is the copy of #{@artist.copies.size}" You need to use double quotes to evaluate the embedded expression. HTH, Nicholas On Nov 28, 9:09 am, Nish Patel <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I see!!! it works now thanks you very much Nicolas the only thing is > that the message doesnt show up i dont know why and when i change it to > a notice the only thing showing on the page is This is the copy of > #...@artist.copies.size} > as the message, strange > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Many thanks Nicolas for your help you have helped me alot on this and i cant thank you enough, going home now it has been a long day in the office i will see what i can do tomorrow but once again thankyou my friend! Kind Regards Nish -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Yes Nicolas the flash message still falls over everytime the error ActiveRecord::StatementInvalid in ArtistsController#copy Mysql::Error: Unknown column ''artists.copy_id'' in ''where clause'': SELECT count(*) AS count_all FROM artists WHERE (artists.copy_id = 112) RAILS_ROOT: C:/INSTAN~1/rails_apps/example4/config/.. its doesnt like this does it: flash[:message] = "This is the copy of #{@artist.copies.size}" -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
ok, i made another column on mysql called copy_id. Then the message didnt fall but now it keeps on show this is the copy of 1, all the time, so close!!!! i looked at the database and it seems to be working fine, i only need the differences of the keys and thats my answer!!!, going home now -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Nish, are you going back to the original screen that you made a copy from, or a you making a copy from the new one - that''s why it would be showing a size of one. Cheers, Nicholas On Nov 28, 11:42 am, Nish Patel <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> ok, i made another column on mysql called copy_id. Then the message > didnt fall but now it keeps on show this is the copy of 1, all the time, > so close!!!! i looked at the database and it seems to be working fine, i > only need the differences of the keys and thats my answer!!!, going home > now > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Nicholas Henry wrote:> Nish, are you going back to the original screen that you made a copy > from, or a you making a copy from the new one - that''s why it would be > showing a size of one. > > Cheers, > Nicholas > > On Nov 28, 11:42 am, Nish Patel <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>Basically what i wanted was to click on the link "copy", then basically edit the copied record but with record pre populated already so all i have to do is to change a few things so this would be "edit" then basically go on to "show" to see the final changes etc, then click on to the link to go back to "list" thanks Nicolas -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Nicolas sorry i understand what you mean it works!!! thank you so much for your help you have been brilliant, i cant believe how helpful these forums can be, thankyou so much!!!!!!!!!!!!!!!!!!!!! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
You''re very welcome, I am pleased we got you on the right track :) On Nov 29, 4:51 am, Nish Patel <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Nicolas sorry i understand what you mean it works!!! thank you so much > for your help you have been brilliant, i cant believe how helpful these > forums can be, thankyou so much!!!!!!!!!!!!!!!!!!!!! > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---