Hi, Ruby Newbie here, with a question. I''ve written rails web app, and I''d like to have the controller log the post data into the info log to keep track of how users are using my app. Is there a way to reference all of the POST data in bulk, or will I have to call out each field separately? The form has a lot of fields, so maintaining the logging feature will be a pain if it can''t be done in one wack, by referencing a certain hash or something. Any advice greatly appreciated. scafativ -- Posted via http://www.ruby-forum.com/.
Vc Scafati wrote:> a pain if it can''t be done in one wack, by referencing a certain hash or > something. > > Any advice greatly appreciated. >What about the params hash? -- Posted via http://www.ruby-forum.com/.
7stud -- wrote:> > What about the params hash? >And the standard library module yaml can format the output for you: require ''yaml'' params = {:name => "Ted", :age => 32, :email => "xxx-bGHiYpY0Uss@public.gmane.org"} puts YAML.dump(params) --output:-- ----- :age: 32 :email: xxx-bGHiYpY0Uss@public.gmane.org :name: Ted -- Posted via http://www.ruby-forum.com/.
Vc Scafati wrote:> Hi, > > Ruby Newbie here, with a question. I''ve written rails web app, and I''d > like to have the controller log the post data into the info log to keep > track of how users are using my app. Is there a way to reference all of > the POST data in bulk, or will I have to call out each field separately?Do you mean write something like: puts params[:name] puts params[:age] puts params[:email] ... ... ??? Like most programming languages, ruby has loops, so you could always write: params = {:name => "Ted", :age => 32, :email => "xxx-bGHiYpY0Uss@public.gmane.org"} params.each do |key, val| puts "#{key} = #{val}" end --output:-- name = Ted age = 32 email = xxx-bGHiYpY0Uss@public.gmane.org That would allow you to format the data anyway you want. One advantage of using yaml is that you can later use a method in another program to reload the data back into a hash to analyze the data, i.e. output all the users by age category or by location. yaml has the advantage that it is both human readable and can be reloaded into a hash. You can even edit the yaml file by hand. Similar to yaml is marshall--except marshal is built into ruby and it is faster. However, the files marshal generates are not human readable and not editable by hand. Marshal is used to store ruby data in a program that is stored in hash, array, or object of a class, and then reload the object at a later date for use in another program. -- Posted via http://www.ruby-forum.com/.
ActionController::Request#body http://api.rubyonrails.org/classes/ActionController/Request.html#M000701 dwh 7stud -- wrote:> Vc Scafati wrote: > >> Hi, >> >> Ruby Newbie here, with a question. I''ve written rails web app, and I''d >> like to have the controller log the post data into the info log to keep >> track of how users are using my app. Is there a way to reference all of >> the POST data in bulk, or will I have to call out each field separately? >> > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---