How to Use the Ruby Case Statement in the Rails Controller

104 11
    • 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...
Subscribe to our newsletter
Sign up here to get the latest news, updates and special offers delivered directly to your inbox.
You can unsubscribe at any time

Leave A Reply

Your email address will not be published.