How to add a new action to the existing controller?

后端 未结 4 764
南笙
南笙 2020-12-13 02:19

I\'m pretty new in Rails. Sorry for the noob question.

I\'ve create a new controller: rails new controller Say hello goodbye

How can i add a new

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-13 02:55

    def hello
      @hello = "hello"
    end
    
    def goodbye
      @goodbye = "goodbye"
    end
    

    then in /config/routes.rb

    get 'foo/hello'       ## foo is the name of your controller
    get 'foo/goodbye'
    

    Remember to create the views too: views/foo/hello.html.erb that may look like this:

    Say <%= @hello %>
    

    views/foo/goodbye.html.erb that may look like this:

     Say <%= @goodbye %>
    

提交回复
热议问题