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

  • Home
  • SEARCH
  • 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 8289201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:27:12+00:00 2026-06-08T12:27:12+00:00

Good morning, In my Ruby On Rails application I am trying to build a

  • 0

Good morning,
In my Ruby On Rails application I am trying to build a stat counter for wins and for losses.
These stats are displayed in the sidebar of my page, which is always visible. For these values i use a model named Stats. The stats should be available global, since I want to display them on every side so they were put into application_helper.rb. I also have two actions, that should be called if you click on the add win / or add loss link, which is only displayed for admins. After clicking the link you get redirected to the main page. At the moment, both counters increase each time someone enters the site or refreshes it. Can you please help me, I am looking to solve this problem now for several hours and i still don’t get it.

My application_helper

module ApplicationHelper

def stats
    @stats = Stats.find(1)
end
def addwin
    @stats = Stats.find(1)
    @stats.update_attribute(:wins, @stats.wins+1)
end

def addloss
    @stats = Stats.find(1)
    @stats.update_attribute(:loss, @stats.loss+1)

end

end

An extract of my application.html.erb file, where the sidebar is located:

    <tr><td>Dotards StatsTracker</td></tr>
    <tr><td>Wins: </td><td style="color:green"><%= stats.wins%></td></tr>
    <tr><td>Losses: </td><td style="color:red"><%= stats.loss%></td></tr>

    <hr>
    </table >
    <%if user_signed_in? && current_user.admin? %>
        <small><%= link_to "Add Win", news_index_path(addwin) %>|<%= link_to "Add Loss", news_index_path(addloss)%></small>
    <% end %>

Would be awesome if someone could help me, because I don’t know what else i can do.
Thank you very much in advance.

  • 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-08T12:27:14+00:00Added an answer on June 8, 2026 at 12:27 pm
    news_index_path(addwin)
    

    calls the add win method directly on generation of the page, that’s why the counter is increased.

    move the two methods to an appropriate controller (maybe news_controller?) and create routes in config/routes.rb like this:

    match '/addwin', to: 'news#addwin'
    

    then you get path helpers which you can use like this:

    link_to "Add Win" addwin_path
    

    run rake routes to see the helper names generated.

    addition: I would also consider your Singleton Stat into a model, and define methods there which are just used by the controller.

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

Sidebar

Related Questions

Good morning, I am currently developing a java web application that exposes a web
Good morning - I'm an intermediate-level developer who wants to build on online data-driven
Good Morning All, I am creating an application to display List of applications with
Good morning friendly Flashers ;) So I've been trying since yesterday to just load
Good Morning All, I am developing a new ASP.net MVC web application. Part of
Good Morning, Has anyone attempted to convert/migrate an ASP.net MVC web application project to
Good Morning, I have a SharePoint site that I've been trying to fix up
good morning, I was trying the SharedPreferences Class and I have created two classes,
Good morning, I have to use the properties from DeviceNetworkInformation in my application. (http://msdn.microsoft.com/en-us/library/microsoft.phone.net.networkinformation.devicenetworkinformation(v=vs.92).aspx)
Good morning, I am the developer of a medium sized PDA application that will

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.