I am a new user of rails and web languages in general and I am trying to understand the method calling functioning. A method in my controller:
def azer
@usr=User.all
@test = User.first
def incr()
@test.nbr_set = @test.nbr_set+1
@test.save
end
incr()
end
The route : get "test/azer"
azer.html.erb :
<%= @test.username %></br>
<%= @test.nbr_set %></br>
When I refresh the page, nbr_set is increasing but I don't want to do that with this way.
In a first time, how can I define a route that will call my incr() method? Because now, the incr() method is automatically called and it's a problem.
Then, is it possible to make an ajax button who will increase nbr_set without refreshing the page? How can i make it?
Finally, I am trying to learn ajax with ruby but it's difficult and I don't understand how I can load a html.erb file who while update my database without refreshing my page.