Mode:
Duration:
1
Coding works best on desktop or with an external keyboard.
Coding works best on desktop or with an external keyboard.
Use a service object to manage counter state.
# app/services/counter_service.rb
class CounterService
@@count = 0
def self.get_count
@@count
end
def self.increment
@@count += 1
end
def self.reset
@@count = 0
end
end
# app/controllers/counter_controller.rb
class CounterController < ApplicationController
def show
render json: { count: CounterService.get_count }
end
def increment
CounterService.increment
redirect_to '/counter'
end
def reset
CounterService.reset
redirect_to '/counter'
end
endRuby on Rails (Rails) is a full-stack, server-side web application framework written in Ruby. It emphasizes convention over configuration, DRY (Don't Repeat Yourself) principles, and rapid development.
Origin & Creator
Ruby on Rails was created by David Heinemeier Hansson and first released in 2004.
Industrial Note
Rails is ideal for startups and projects requiring fast prototyping, robust full-stack development, and applications with database-driven backends.