2014年6月17日 星期二

RoR Hello World

MVC Model in Rails

1. Generator a controller

rails generate controller welcome

      create  app/controllers/welcome_controller.rb
      invoke  erb
      create    app/views/welcome
      invoke  test_unit
      create    test/controllers/welcome_controller_test.rb
      invoke  helper
      create    app/helpers/welcome_helper.rb
      invoke    test_unit
      create      test/helpers/welcome_helper_test.rb
      invoke  assets
      invoke    coffee
      create      app/assets/javascripts/welcome.js.coffee
      invoke    scss
      create      app/assets/stylesheets/welcome.css.scss



2.Add new setting in routing file (config/routes.rb)

get "welcome/say_hello" => "welcome#say"


3. edit controller fileopen app/controllers/welcome_controller.rb, and then ass a say method.

class WelcomeController < ApplicationController 
    def say 
    end
end


4.add app/views/welcome/say.html.erb

<h1>Hello, World!</h1>


沒有留言:

張貼留言