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,
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
After this step.
After this create a view in edit.html.erb under views:
Go to counter.rb model and do the following:
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
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.