Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7604571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:56:39+00:00 2026-05-30T23:56:39+00:00

I am calling a random Post and allowing users to +1 or -1 the

  • 0

I am calling a random Post and allowing users to +1 or -1 the post before loading another post. My model generates a random record at the URL /posts/random using the following.

Post.rb // Model

def self.find(*args)
  if args.first.to_s == "random"
    Post.find :first, :offset => rand(Post.count)
  else
    super
end

This code generates a random post when the user visits posts/random. However, I also defined a thumbs_up and thumbs_down field in the database that correspond to a thumb_up and a thumb_down image that when clicked, need to +1 or -1 the value in the database, before redirecting to another /posts/random. My understanding is that to do this I need to invoke the PUT update method, however, since my URL is posts/random instead of posts/1, how can I do this? Do I need to alter my routes?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T23:56:40+00:00Added an answer on May 30, 2026 at 11:56 pm

    First thing is that you’d need is an instance variable representing the random post so that you could use it in the thumbs up and thumbs down links. Then you need to make sure that those links look something like this:

    <%= link_to "Thumbs Up", post_path(@post, thumbs_up: 1), method: :put %>
    <%= link_to "Thumbs Down", post_path(@post, thumbs_down: 1), method: :put %>
    

    That way, when in your update action for your posts controller, you can do something like this:

    @post.update_attributes(thumbs_up: @post.thumbs_up + params[:thumbs_up],thumbs_down: @post.thumbs_down + params[:thumbs_down] )
    

    That is only a start, but I think that should get you going in the right direction.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Calling the ajax called URL works well without ajax eg. http://localhost/ci/controller/method/param_value . But using
I'm using the following code to generate a random string: <?php function random_string( )
When calling CoInitializeEx , you can specify the following values for dwCoInit : typedef
Using CoreData (on an iPhone app) I generated my entity classes from the model
Here is a function in PHP that generates a random number between 1 and
Suppose I wish to have 2 functions, one that generates a random integer within
I want to repeat a random number sequence generated by a legacy software using
I am using a System.Random object which is instantiated with a fixed seed all
All, I have implemented a code that generates 2 random prime numbers and the
Given a consistently seeded Random: Random r = new Random(0); Calling r.Next() consistently produces

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.