Hello, Can somebody help me on how to open a file and show it on a text area, and be able to edit it and save it again. Thanks, --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
in ruby there is the class File: http://www.ruby-doc.org/core/classes/File.html to get the contents of your file try something like: my_file = File.new(path_to_file, ''r'') @my_file_content = my_file.read my_file.close now you can show your content inside the text area (you should know how to build a simple form for it). after editing it, back in your controller write the updated contents to the file: updated_content = params[:whatever] my_file = File.new(path_to_file, ''w'') my_file.write(updated_content) my_file.close --~--~---------~--~----~------------~-------~--~----~ 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 MaD, I''ll try it out. On Feb 12, 2:55 am, MaD <mayer.domi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> in ruby there is the class File:http://www.ruby-doc.org/core/classes/File.html > > to get the contents of your file try something like: > my_file = File.new(path_to_file, ''r'') > @my_file_content = my_file.read > my_file.close > > now you can show your content inside the text area (you should know > how to build a simple form for it). > > after editing it, back in your controller write the updated contents > to the file: > updated_content = params[:whatever] > my_file = File.new(path_to_file, ''w'') > my_file.write(updated_content) > my_file.close--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---