this is really basic, basic, basic stuff. you should really read up on
your basics instead of asking people to code for you.
anyway, in your controller get all the entries you want to desplay:
@entries = Entry.all
then in your view iterate through all entries:
<% for entry in @entries do %>
<Div id='<%= entry.id %>'style='color:<%= entry.color %>'><%=
entry.when %></Div>
<% end %>
of course you could use partials as well. but as you obviously don't
know much about rails, I won't go into that here. seriously learn some
basics.
#1
well, if you just go like this:
entry.when - entry.to
you'll get the seconds in between both times. you can then calculate
minutes, hours, days, ...
#2
filling in the values should then be a piece of cake.
#3
what you are looking for is not an array, but a hash. shouldn't be
problem, once you've figured out how to write some ruby-code.
i'm still not sure, what exactly you are trying to do, but try
something like this:
# create hash
hash = Hash.new
# iterate through your entries
for entry in @entries do
# create date
date = entry.when.to_date
# calculate range in days
days = ((entry.to - entry.when)/86400).round)
# for every day add a value to hash
days.times do
# build the string
string = "<Div id='1' style='color:" + entry.color + "'>" +
entry.description + "</Div>"
if hash.has_key?(date)
# append string
string = hash[date] + string
end
# add to hash
hash.merge!({date => string})
# increase date
date = date.advance(:days => 1)
end
end
# iterate through your hash
hash.each_pair do |key, value|
# output
puts key + '=>' + value
end
i should mention a few things:
1) i did this because i was bored. for the future, try it on your own
and ask if you are stuck. post your code, so people can spot the error
for you. don't expect people to code for you.
2) i did not test the code above. i just hacked it into this post.
there may be errors in it.
3) your page will not work with all the divs having the same id. id
should be unique, but as php-coder you should already know that...
Arrays do not have keys and values. Ruby is not php. An orderedhash is
like a php associative array.
Your description of your problem is not clear enough. Ask simple clear
questions and we can help then. You seem to be having algorhithm
problems, not language problems. Explain your algorhithm to us on
pseudocode and show the ruby you've tried and then we will help where
you're stuck.