How to Use the Ruby Case Statement in the Rails Controller
- 1). Open a Controller from your Rails project. The Controllers are located in the "controllers" directory.
- 2). Put the cursor inside the desired method. A method looks something like this:
def method
// some code here.
end - 3). Add the following code to the controller method:
case foo
when 1
puts "1"
when 2
puts "blah blah"
end
Case statements may be used in this way in Rails controllers.
Source...