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 => "[email protected]"}
params.each do |key, val|
puts "#{key} = #{val}"
end
--output:--
name = Ted
age = 32
email = [email protected]
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/.
--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---