Posts [ 17 ]

Topic: Trying to create a site with a homepage that changes every day

I am designing a site that has a new picture on the homepage every day. The problem is that I can not see clearly how to do it. How would you code the site to, basically, load a new homepage-pic everyday? I could really use some guidance (links to tutorials, etc) on how to:

(1) set up the database, controllers, views, etc. to automatically pull the new picture everyday.

(2) schedule images ahead of time to be automatically updated on the homepage.

Re: Trying to create a site with a homepage that changes every day

@num.to_s --- @num represent each day of the month. If the months has 30 days then it will be 1..30 or else it will be 1..31 if it's 31 day. with to_s you simply put the day and convert it to a string.

@num is independant of the month or year. If you want to store pictures of many months and have it change each day of the year then the technique is a bit different and you have to use Time.month

Re: Trying to create a site with a homepage that changes every day

I was able to get the image to display every day. Now I am trying to figure out how to get the image to be from a database. I would like users to be able to comment on the image and to have those comments stored with the image.

Any guidance or advice would be appreciated.

Last edited by Starflyer59 (2011-01-21 05:42:21)

I'm so abstract that automatic doors at grocery stores do not even open for me. - @thatdankent

Re: Trying to create a site with a homepage that changes every day

Why would you want to store your pictures in a database anyway (unless there are tons of datas) ?

There are plenty of ways to do that:

Just define a model which is going to be called day (rails g model day if your on rails 3)then define the day in your model ( t = Time.new @num = t.day) and don't forget to convert it to string (.to_s)

Put the attached avatar paperclip statement in it.and then follow the instruction in the tutorialand change the view like this

<%= image_tag(@day.avatar.url) %>

If you want to strore more then a month, then add def month and def myday in your model and call @day.month.myday.avatar.url

I didn't test it but it should theoreticaly work. The best way is to experiment

Re: Trying to create a site with a homepage that changes every day

Thanks Henrik41. I do not necessarily want the images "in" a database. All I want is a way to call a new picture to the homepage each day and to be able to have people comment on that picture (and for those comments to remain associated with that day's picture).

I am going to try your most recent suggestion.

I'm so abstract that automatic doors at grocery stores do not even open for me. - @thatdankent

Re: Trying to create a site with a homepage that changes every day

hi,i have done my home page with image changing every day by calling the id to home page.but now i want to make a 3 image box with changing according to day. previously i have done by calling the id,so that all the 4 images are showing the sane id image.how i can made it possible by calling image id from database for seperate image in same home page.

Re: Trying to create a site with a homepage that changes every day

Well, Johpaul, I do not understand what you are looking for. Does the 3 image box change every day? Or just a single image in the box? Where does the 4th image come from? Not sure what id image means, either. Need more specifics.

I'm so abstract that automatic doors at grocery stores do not even open for me. - @thatdankent

Re: Trying to create a site with a homepage that changes every day

hi,i have already made a picture to change it every day.by find by sql and return it id to home page controller.so that it gets the id and show the image.but now i want to show another 3 image in same home page.but i am getting the same image in 3 box as same as the previous defined image.so how i can get the required image in my field.