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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:44:36+00:00 2026-05-26T03:44:36+00:00

I’m making a click counter, i.e, when a user clicks a button, we want

  • 0

I’m making a “click counter”, i.e, when a user clicks a button, we want to count the clicks. In my case, the user is visiting a page for coupons, and I want to count the number of time she clicks the print button.

To set this up, I created a “click” model.

class Click < ActiveRecord::Base
    belongs_to :coupon
end

And a click controller with a create method.

class ClicksController < ApplicationController
  def create
    @coupon = Coupon.find(params[:id])
    @coupon.clicks.create

    respond_to do |format| 
        format.html { redirect_to @coupon }
    end
  end
end

And I’ve created a migration like this:

class CreateClicks < ActiveRecord::Migration
  def self.up
    create_table :clicks do |t|
      t.integer :coupon_id

      t.timestamps
    end
  end

  def self.down
    drop_table :clicks
  end
end

Then I configure my routes like so:

map.resources :coupons, :has_many => :clicks

map.resources :clicks
map.connect 'coupons/:id/clicks', :controller => 'clicks', :action => 'create'

And then the button that ads 1 click:

<%form_remote_tag :url => coupon_clicks_path(@coupon) do %>
<% submit_tag 'click!' %>
<% end %> 

Then I browse to /coupons/4/clicks …. and it gives me an error saying that it can’t find the page. 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-05-26T03:44:37+00:00Added an answer on May 26, 2026 at 3:44 am

    As @Matthew mentioned it looks like you’re using Rails 2, the reason your route isn’t recognized is that you’re defining it after the resources of coupons. They both share the part of the route ‘/coupons’ so that resource’s REST routes are overriding 'coupons/:id/clicks'.

    As is says in the routes.rb default comments: The priority is based upon order of creation, first created -> highest priority.

    So to get your 'coupons/:id/clicks' route to of a higher priority move it to the top of the routes.rb file.

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

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Basically, what I'm trying to create is a page of div tags, each has
I would like to count the length of a string with PHP. The string
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but

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.