SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    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

  2. #2
    SitePoint Addict
    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.

  3. #3
    SitePoint Enthusiast
    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!

  4. #4
    SitePoint Enthusiast
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •