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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:48:35+00:00 2026-05-29T15:48:35+00:00

I want to create a counter example where in the variable increments when ever

  • 0

I want to create a counter example where in the variable increments when ever the user presses a button on the webpage(view)

I have created the ruby program for the counter like this:

   def counter(x = 0)
     x+=1
     puts "The current value is #{x}"
   end

I have saved this as counter.rb. Then for the view I created another file called counter.erb But I dont know where to call this rb file and should I use <%= %> embedded ruby tags? Totally confused.

Another thing is the method counter’s parameter should be linked to the button clicks.

Please guide me

Thanks,

  • 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-29T15:48:38+00:00Added an answer on May 29, 2026 at 3:48 pm

    Ok this is basic and you should be knowing this but still, I will tell you. The question is also vague so I will assume that you have a counter which is a number and a name for the counter. This is how you update any column from scratch.So first create

          rails generate scaffold counter count:integer name:string
    

    After this step.

          def update
            @counter = Counter.find(params[:id])
            if @counter.update_attributes(params[:counter])
                   redirect_to @counter, :flash => { :success => "Profile updated." }
            end
          end
    

    After this create a view in edit.html.erb under views:

    <%= form_for(@counter) do |f| %>
        <div class="field">
          <%= f.label :name %><br />
          <%= f.text_field :name %>
        </div>
        <div class="field">
          <%= f.label :count %><br />
          <%= f.text_field :count %>
        </div>
        <div class="actions">
          <%= f.submit "Update" %>
        </div>
    <% end %>
    

    Go to counter.rb model and do the following:

    class Counter < ActiveRecord::Base
      attr_accessible :count, :name
    end
    

    You dont have to add anything in the routes file because it already has the update resource.
    Now open the browser and if you say

    localhost:3000/counter/1/update
    

    after creating the first counter value then you can update stuff from there.

    This is how you updating can be done in ruby on rails. If you need more explanation regarding your code you should check the api documentation for rails it is a good start. I am a beginner too.

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

Sidebar

Related Questions

i want create image animation , i have 50 images with png format now
I want to create a game-like ping in Javascript, just like the game Counter
I want to create a windows phone 7.1 application to display a messaging counter.
All, I created a plugin using the create plugin with a view wizard, which
Hello I want to create a performance counter named as FileCopierApp , this should
I want to write simple counter for links/tags. So I have tags and random
I have the following table schema: create table SerialNo2( IncarnationID_UID counter primary key, Mark
I want create a drop shadow around the canvas component in flex. Technically speaking
I want create a excel with Apache POI in java and I must insert
I want to create a Java application bundle for Mac without using Mac. According

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.