Controller method to manage SMS subscriptions I have a huge method in my controller that is not DRY and just could use some general TLC. I'm new to ruby and I have not refactored my own code before, only contrived code you find on tutorials. Below I will show my controller, just to be clear I'm not looking for a full answer just maybe where I should start and some helpful tips. 

def process_message(message, subscriber)
  if message == "tulip" || message == "stem"
    # If the user has subscribed flip the bit
    # and let them know
    subscribed = message == "tulip"
    subscriber.update(subscribed: subscribed)

    # Respond appropriately
    output = "You are now subscribed for updates."
    unless subscriber.subscribed
      output = "You have unsubscribed from notifications. Test 'TULIP' to start receieving updates again"
    end

    subscriber.add_to_group("visitor")

  elsif message == "dancers"
    subscribed = message == "dancers"
    subscriber.update(subscribed: subscribed)

    subscriber.add_to_group("dancers")

    output = "You have been subscribed to the Dancers list"

  elsif message == "staff"
    subscribed = message == "staff"
    subscriber.update(subscribed: subscribed)

    subscriber.add_to_group("staff")

    output = "You have been subscribed to the Staff list"

  elsif message == "volunteer"
    subscribed = message == "volunteer"
    subscriber.update(subscribed: subscribed)

    subscriber.add_to_group("volunteer")

    output = "You have been subscribed to the Volunteer list"

  else
    # If we don't recognize the command, text back with the list of
    # available commands
    output = "Sorry, we don't recognize that command. Available commands are: 'TULIP' or 'STEM'."
  end

  output
What I noticed is that there are very few differences between what's happening within the sections that the 'dancers', 'staff', and 'volunteer' messages take you through. Because the only thing that really changed between the three was the word within the message itself, I decided to combine them and use the message variable.

def process_message(message, subscriber)
  if standard_groups.include?(message)
    subscriber.update(subscribed: true)
    subscriber.add_to_group(message)

    "You have been subscribed to the #{message.capitalize} list"
  elsif message == 'tulip' || message == 'stem'
    subscriber.update(subscribed: message == 'tulip')
    subscriber.add_to_group('visitor')

    return 'You are now subscribed for updates.' if subscriber.subscribed
    "You have unsubscribed from notifications. Test 'TULIP' to start receieving updates again"
  else
    "Sorry, we don't recognize that command. Available commands are: 'TULIP' or 'STEM'."
  end
end

def standard_groups
  %w(dancers staff volunteer)
end


I was able to remove the output variable by leaving the string that you want to return as the last line that will run within the method. The exception is the line 'returned' if subscriber.subscribed comes back true.

I moved the common messages to an array so that you can easily add more in the future.

I considered separating the conditional for 'tulip' and 'stem' into 2 individual conditionals, but to me it made more sense to keep the "exceptions" together, especially since they share the 'visitor' group. For increased legibility, you may choose to separate them.