[Linux - Ruby on Rails 웹사이트 만들기] 2. 웹 페이지 만들기

1. 새 controller 만들기

 

:~/mySimpleApp$ rails generate controller main index

 

       create  app/controllers/main_controller.rb

       route  get 'main/index' main controller (디폴트 생기는 거)의 index 함수 실행

      invoke  erb

      create    app/views/main

      create    app/views/main/index.html.erb index template. Directory의 default 파일 -> index.html

      invoke  test_unit

      create    test/controllers/main_controller_test.rb

      invoke  helper

      create    app/helpers/main_helper.rb

      invoke    test_unit

      invoke  assets

      invoke    coffee

      create      app/assets/javascripts/main.coffee

      invoke    scss

      create      app/assets/stylesheets/main.scss

 

이 명령은 index 액션을 하는 main 이라는 이름의 컨트롤러를 만든다.

main_controller.rb는 main 파라미터에서 만들고 index.html.erb는 index 파라미터에서 만든다.

 

 

 

2. index.html.erb 변경

 

/views/main/index.html.erb

내용을 html문에 맞게 사용자에게 보이고 싶은 모습으로 설정

 

 

 

3. routes.rb 변경

 

config/routes.rb

내용은 변경하기 전,

Rails.application.routes.draw do
  get 'main/index'
end

라고 되어있을 것이다. 이걸

Rails.application.routes.draw do

root 'main#index'

 

end

로 수정한다.

 

root 'main#index' 는 레일즈가 어플리케이션의 root에 요청들을 main 컨트롤러의 인덱스 작업에 매핑하도록 한다.

 

 

728x90