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 6646565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:25:56+00:00 2026-05-26T00:25:56+00:00

Ok, I have a simple question. I am new to RoR and I created

  • 0

Ok, I have a simple question. I am new to RoR and I created a scaffold for an item. I then wanted to add a link that, when pressed, incremented a counter. What I am having trouble with is routing. I modeled this functionality after the destroy/delete link and method. Here is my code:

index.html.erb:

  ...
  <td><%= link_to 'Destroy', post, method: :delete %></td>
  <td><%= link_to 'increment', post, method: :increment%></td>
  ...

post_controller.rb:

  def vote
    @post = Post.find(params[:id])
    @post.counts = @post.counts + 1
    @post.save

    respond_to do |format|
      format.html { redirect_to post_url }
      format.json { head :ok }
    end
  end

When I try and click on the link, I get a routing error:

Routing Error

No route matches [POST] “/posts/25”

is there a step I am missing? Do I have to add some routing stuff to get this working?

  • 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-26T00:25:56+00:00Added an answer on May 26, 2026 at 12:25 am

    Ok, hang in here with me, there’s a few fixes needed:

    The :method param in the link_to function is not referring to the controller method, it is referring to the HTTP method. So acceptable values would be ‘:post’, ‘:delete’ etc.

    More info: http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to

    In this case we probably want to set :method to :post for the increment link, which we will need to match with the route we will create now.

    To access the vote action you have created, we need to add it to the routes file. You probably have something like this:

     resources :posts
    

    We need to add an action (vote), that will apply to a member of the posts resource, so we change that to this:

    resources :posts do
      member do
        post 'vote'
      end
    end
    

    Now that we have the correct route, we can use the route helper method in the link_to helper (to see a full list of routes run rake routes at the command line). So in your link_to replace post with vote_post_path(post). If we include our earlier change about the :method we get:

    <%= link_to 'increment', vote_post_path(post), method: :post %>
    

    Hope this helps to fill in some blanks for you!

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

Sidebar

Related Questions

I'm new to Java so I have a simple question that I don't know
I have a simple question,in the below example when i created a new TransitionManager
Simple question. I have a new list and an old list. In Java is
Hey guys I have what should be a simple question, but I am new
I'm rather new to WPF, so maybe this is a simple question. I have
New to Python, have a simple, situational question: Trying to use BeautifulSoup to parse
I am new to Repository concept and get some questions. I have created simple
i have a simple question, there is a function with parameter emp_id that opens
I am new to WCF and have a simple question... My DataContract class returns
I'm really new in Android programming, so I have a simple question getting a

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.