Rails Controller Action
Default template
When creating new controller with action
rails generate controller items index
index action is created
class ItemsController < ApplicationController def index end end [/ruby] index operation is nothing. the default template is <b>app/views/items/index.html.erb</b>. If action is blank, default template is called. <h3>Use other template</h3> [ruby] render :action => 'actioname' render 'actionname'
actionname is your action method in contrlller
Call other controller template
def index render "words/show" end
words is other controller.
Output Text
Use :text
render :text => 'Hello World'
Example
class ItemsContrller < ApplicationController def index render :text => 'Hello Ruby!' end end
Output nothing
render :nothing => true
With status
render :text => 'Bad world', :status => 404
Layout
text doesn’t include default layout template.
layout option includes layout(header, footer etc…)
class ItemsController < ApplicationController def index render :text => 'Hello World', :layout => true end end