Small doubt HELP me

Hi ,

I have table like this
 ---------------------------------------------------------------
|id | what   | when      | color  |   to      | description     |
---------------------------------------------------------------
|1  | test   |2009-02-01 | red    |2009-02-15 |    yyyyy        |
---------------------------------------------------------------
|2  | test2  |2009-02-02 | green  |2009-02-14 |    xxxxx        |
-----------------------------------------------------------------

i want output like this,

2009-02-01=><Div id='1’style=‘color:red’>yyyyy
2009-02-02=><Div id='1’style=‘color:red’>yyyyy<Div
id='2’style=‘color:green’>xxxxx
2009-02-03=><Div id='1’style=‘color:red’>yyyyy<Div
id='2’style=‘color:green’>xxxxx
2009-02-04=><Div id='1’style=‘color:red’>yyyyy<Div
id='2’style=‘color:green’>xxxxx
2009-02-05=><Div id='1’style=‘color:red’>yyyyy<Div
id='2’style=‘color:green’>xxxxx
2009-02-06=><Div id='1’style=‘color:red’>yyyyy<Div
id='2’style=‘color:green’>xxxxx
2009-02-07=><Div id='1’style=‘color:red’>yyyyy<Div
id='2’style=‘color:green’>xxxxx
2009-02-08=><Div id='1’style=‘color:red’>yyyyy<Div
id='2’style=‘color:green’>xxxxx
2009-02-09=><Div id='1’style=‘color:red’>yyyyy<Div
id='2’style=‘color:green’>xxxxx
2009-02-10=><Div id='1’style=‘color:red’>yyyyy<Div
id='2’style=‘color:green’>xxxxx
2009-02-11=><Div id='1’style=‘color:red’>yyyyy<Div
id='2’style=‘color:green’>xxxxx
2009-02-12=><Div id='1’style=‘color:red’>yyyyy<Div
id='2’style=‘color:green’>xxxxx
2009-02-13=><Div id='1’style=‘color:red’>yyyyy<Div
id='2’style=‘color:green’>xxxxx
2009-02-14=><Div id='1’style=‘color:red’>yyyyy<Div
id='2’style=‘color:green’>xxxxx
2009-02-15=><Div id='1’style=‘color:red’>yyyyy

Note:

The ‘id’ of div is the value of ‘id’ field in database
The ‘color’ of div is the value of ‘color’ field in database
The ‘description’ of div is the value of ‘description’ field in database

can any one help in this for me…

Please do a tutorial on rails

Blog: http://random8.zenunit.com/
Learn rails: http://sensei.zenunit.com/

On 04/02/2009, at 9:42 PM, Shankar G.
<[email protected]

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 %>
<% 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.

Hello,

This is not as regular we do for all tables.Look at the table you 

can see two fields ‘when’ and ‘to’. What I need is

#1 must find the range of dates between ‘when’ and ‘to’ fields,
#2 Then I must fill the value for each date with the corresponding
values.
#3 Should make an array with key as date and div content as value.

Hope you got It.Anyhow thanks for reply.

cheers,
shankar.

Can you explain with a bit of code, It will be helpful for me apologizes
I’m newbie to ROR and I’m a PHP developer.I would like to develop
calendar using ROR when I am ti display the events I got struck here.

#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 = “

” +
entry.description + “

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…

You don’t need a do when you’re using for in

Blog: http://random8.zenunit.com/
Learn rails: http://sensei.zenunit.com/

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.

Blog: http://random8.zenunit.com/
Learn rails: http://sensei.zenunit.com/

On 05/02/2009, at 6:07 PM, Shankar G.
<[email protected]

Ya thanks for your post, hope it will be helpful.

Nah, he has string fields

Blog: http://random8.zenunit.com/
Learn rails: http://sensei.zenunit.com/

Your English Has confusions!

Blog: http://random8.zenunit.com/
Learn rails: http://sensei.zenunit.com/

On 05/02/2009, at 6:27 PM, Shankar G.
<[email protected]

For…in doesn’t take do!

Obviously you’re not testing your code before you suggest it!!!

Blog: http://random8.zenunit.com/
Learn rails: http://sensei.zenunit.com/

You’re right I skim them. Sorry about that. Didn’t realize you could
use do there. It’s definitely optional tho. I fail :slight_smile: thanks, I learn
something.

Blog: http://random8.zenunit.com/
Learn rails: http://sensei.zenunit.com/

hallo julian,

you already said the following:

You don’t need a do when you’re using for in
you’re right on that one, but you don’t have to tell me twice:
For…in doesn’t take do!
especially as this is just wrong. try it yourself:
for number in [1, 2, 3] do
puts number
end

Obviously you’re not testing your code before you suggest it!!!
i already said that:
i should mention a few things:
2) i did not test the code above. i just hacked it into this post.
there may be errors in it.
so: obviously you’re not reading a post before you comment on it!