Class: ReactRailsWebpack::CreateExamplePageGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/react_rails_webpack/create_example_page_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_filesObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/react_rails_webpack/create_example_page_generator.rb', line 10

def add_files
  inside 'app' do
    inside 'controllers' do
      copy_file 'react_example_controller.rb'
    end

    inside 'views' do
      FileUtils.mkdir_p 'react_example'

      inside 'react_example' do
        copy_file 'greeting.html.erb'
      end
    end
  end
end

#add_routeObject



26
27
28
29
30
31
32
# File 'lib/react_rails_webpack/create_example_page_generator.rb', line 26

def add_route
  insert_into_file(
    'config/routes.rb',
    "  get 'greeting' => 'react_example#greeting'\n",
    after: "Rails.application.routes.draw do\n"
  )
end


34
35
36
37
38
39
40
41
42
# File 'lib/react_rails_webpack/create_example_page_generator.rb', line 34

def print_next_steps
  puts
  puts "-" * `tput cols`.to_i # print line of dashes
  puts
  puts "Done! Start your Rails server and go to #{"localhost:3000/greeting".blue.bold} to see your React/Rails integration in action!"
  puts
  puts "-" * `tput cols`.to_i # print line of dashes
  puts
end