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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:02:00+00:00 2026-06-14T07:02:00+00:00

I am new to Rails so please have patience. I wanted to implement like

  • 0

I am new to Rails so please have patience.

I wanted to implement “like” on my canteen model, so I created a custom route inside my canteen resource

resources :canteens do
  resources :meals
  resources :comments
  match "/like", :to => "canteens#like", :as => "like"
end

and therefore created this action inside canteens controller, where I just increment a counter

def like    
  canteen = Canteen.find(params[:canteen_id])
  Canteen.increment_counter("likes_count", canteen.id)
  redirect_to canteen
end

So, manually entering the URL localhost:3000/canteens/1/like works just fine, however obviously I want to create a button so I did a

<h2>Likes count</h2>
<p><%= @canteen.likes_count %> likes</p>
<p><%= link_to "Like this canteen", canteen_like_path %></p>

And it doesn’t work. I checked rake routes and it’s there (canteen_like).
What am I doing wrong?

  • 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-06-14T07:02:01+00:00Added an answer on June 14, 2026 at 7:02 am

    You have to pass a Canteen object to the path. If you don’t do that Rails doesn’t know which canteen you meant:

    <%= link_to "Like this canteen", canteen_like_path(@canteen) %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to Ruby and Rails so bear with me please. I have
I'm very new to rails so please forgive my limited knowledge. If I wanted
I'm pretty new in rails so please be patient with my ignorance. I have
I'm very new to Ruby on Rails so please go easy! I've uploaded the
Please bear in mind that I'm totally new to Rails when answering this.My question
I'm starting a new Rails 3.2.6 application. My nested route is failing when I
Starting a new rails project and we have a well-thought-out color palette, and want
I just created a new rails app in Rails 3.1.1, and my application layout
I am new to rails and have just started writing tests using rspec version
I have just started with ruby on rails, have made a new rails project

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.