Sha256: 3328f2c4a04656740ff28e7a9e4e82634c1288428447bdd8ea21ce7218cd7d1d

Contents?: true

Size: 1.42 KB

Versions: 1

Compression:

Stored size: 1.42 KB

Contents

class WelcomeController < ApplicationController

  include MxitRails::Page

  def index
    input :phone_number, 'Enter your cellphone number'

    validate 'Custom validation message' do |input|
      logger.info "Validation: #{input.inspect}"
      # NB Don't put a return here - it causes much unhappiness
      input != 'custom'
    end
    validate :numeric, 'Please enter numeric digits only'
    validate :min_length, 10, 'Numbers must be at least 10 digits long'
    validate :max_length, 11, 'Numbers cannot be longer than 11 digits'

    @time = Time.now.strftime '%H:%M:%S on %A'

    submit do
      if params[:phone_number] == '1234567890'
        redirect_to '/welcome/easter_egg' and return
      end
      logger.info "This won't execute if an error occurred or if error! or redirect! was called"
      redirect_to '/index/success' and return
    end
  end

  def single
    select :select, 'Select an option', {'A' => 'Option A', 'B' => 'Option B', 'C' => 'Option C'}, selected: 'B', numbered_list: true

    submit do
      logger.info "Value: #{params[:select]}"
      redirect_to '/index/success' and return
    end
  end

  def multi
    multi_select :select, 'Select all that apply', {'A' => 'Option A', 'B' => 'Option B', 'C' => 'Option C'}, selected: ['B', 'C'], numbered_list: true

    submit do
      logger.info "Value: #{params[:select]}"
      redirect_to '/index/success' and return
    end
  end

  def easter_egg
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mxit-rails-0.3.0 test/dummy/app/controllers/welcome_controller.rb