[Ruby] Render Template ROR
Next chapter from Generate Controller RoR
How to Render Template :
- Create route ./config/routes.rb
Rails.application.routes.draw do get 'demo/index' get 'demo/coba' get 'demo/iseng' end
- Add method in demo controller ./app/controllers/demo_controller.rb ```bash class DemoController < ApplicationController def index end
def coba end
def iseng render plain: 'test test' end end
3. Create File in ./app/views/demo/main.html.erb
```bash
Testting
Running Server
rails server
Access your web browser
http://localhost:3000/demo/iseng
How Create Template Diffrent Folder Assume we had created file in ./app/views/home/index.html.erb
<h1>Test</h1>
For direction to template in methode iseneg in demo_controller.rb just
class DemoController < ApplicationController
def index
end
def coba
end
def iseng
render 'home/index'
end
end