parm530
4/4/2018 - 3:44 PM

Template

What to include in the template structure

Template

Using render

  • specifies which view to load
class DemoController < ...
  def index
    # will implicitly render the view page located in views/demo/index
    # otherwise you can specify which view to render:
    # render(:template => 'demo/hello') same as below:
    render('demo/hello')
    # render the view inside views/demo/hello
    # since you are in the demo controller, you don't even need to specify demo:
    render('hello')
  end
  
  def hello
  end
end

Using redirect_to

  • Using a redirect sends another new HTTP request to another controller and action
Class DemoController < ...

  def index
    render('hello')
  end
  
  def hello
  
  end
  
  def other_hello
    redirect_to(:controller => 'demo', :action => 'index')
    # if located in same controller:
    # redirect_to(:action => "index")
    
    # you can also redirect to an actual website:
    redirect_to("http://lynda.com")
  end