iT邦幫忙

1

One Month Rails - Day7 - 新增頁面

以one month rails的線上課程及codecademy的Ruby課程,紀錄及分享一個月來學習的歷程及心得。
Step1: 新增Page controller
terminal:
$ rails generate controller Pages home #新增一個Page controller
$ rm public/index.html

Step2: Delete index.html 刪除預設public/index.html檔案,若不刪除這個就無法設定預設的routes為登錄頁

Step3: 設定root config/routes.rb

Testapp::Application.routes.draw do
root :to => 'pages#home'

在井字號之前的”pages”為step1新增的controller, “home”為action
而home則為controller中預設的action “home”

Step4: 設定controller app/controllers/pages_controller.rb

class PagesController < ApplicationController
def home
end
def action
end
end

Step4: Hello world!
新增一個檔案,另存於下列路徑
app/views/pages/hello.html.erb

打上HTML code吧!!
例如:

Hello World!


圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言