Class: Playground::ScriptsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/playground/scripts_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



3
4
5
6
7
8
9
# File 'app/controllers/playground/scripts_controller.rb', line 3

def index
  @scripts = script_paths

  if params[:name]
    @scripts = @scripts.select { |script| script.downcase.match? params[:name].downcase }
  end
end

#newObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/playground/scripts_controller.rb', line 15

def new
  @_script = <<~SCRIPT
  # Access your application domain as if you were in a rails console.
  # There are three ways to run code in the console:

  # 1 - Select all the code from line 5 to 11 and press cmd+Enter
  module HelloWorld
    module_function

    def hello
      "Hello, World!"
    end
  end

  # 2 - Put your cursor on line 14 (no selection) and press cmd+Enter
  HelloWorld.hello

  # 3 - Type "HelloWorld.hello" in the terminal box below and press cmd+Enter
  SCRIPT

  render :show
end

#showObject



11
12
13
# File 'app/controllers/playground/scripts_controller.rb', line 11

def show
  @_script = File.read script_path(params[:name])
end