SitePoint Sponsor |
|
User Tag List
Results 1 to 4 of 4
Thread: "Bury" Button for Shovell?
-
Sep 5, 2007, 21:04 #1
- Join Date
- Nov 2005
- Posts
- 28
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
"Bury" Button for Shovell?
I have gone through the coding examples, and have tried to find out a way to imitate the **** effect of "burying" a story. Basically, it's just a way to decrease the vote by one each time a "bury" button is clicked.
What could I change below to create code to destroy the record? I've used .destroy but it doesn't work!
def vote
@story= Story.find(params[:id])
@story.votes.create
end
-
Sep 6, 2007, 05:48 #2
- Join Date
- Jan 2006
- Posts
- 268
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I would track them seperately (like d.igg does), unless you want the votes to be able to go negative (if more people bury it than vote for it).
However, if you want to just subtract a vote, you have to call destroy on an individual vote, not the array of votes.
Code ruby:def bury @story = Story.find(params[:id]) @story.votes.first.destroy unless @story.votes.empty? end
If you give someone a program,
you will frustrate them for a day;
if you teach them how to program,
you will frustrate them for a lifetime.
-
Sep 6, 2007, 12:15 #3
- Join Date
- Nov 2005
- Posts
- 28
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks, works like a charm! I have a question though regarding the javascript file.
How exactly does the javascript file know when to update? The code you supplied works, but it doesn't update the vote count. It works if i refresh the page. There is also no visual effect.. I think the problem is solely in the vote.rjs file. But, I haven't managed to get it to work.
thanks for your help!
-
Sep 6, 2007, 12:26 #4
- Join Date
- Nov 2005
- Posts
- 28
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Nevermind- got it working flawlessly.
Thanks again! You guys can close the thread if needed!
EDIT: In case anyone else is interested, I had to create another RJS file called "bury". I also think I created a "bury" model as well. Thanks again!Last edited by zac439; Sep 7, 2007 at 12:57.
Bookmarks