In Amber if you want to render a different template with a controller not matching its name, you can just pass the path to it in the render function. Paths in render are by default relative to the views directory, lets look at an example below to illustrate this.

| HomeController

class HomeController < ApplicationController
  def index
    render "index.slang"
  end
end

In this controller, the render method will look for index.slang inside of the views/home/ directory.

The render function look for a template based on these three rules.

  • Is the path provided a full path to an actual template file (this includes directory name and template name)
  • Or is the path provided a folder containing controller or view
  • Is the path provided ending with a .ecr file extension
  • Is the path provided a controller and at this point strip the _controller from its name and use the rest

Now we can see how the logic work, so we know that if we provide a full path (relative to the views directory), it will render that template.

class HomeController < ApplicationController
  def index
    render "post/index.slang"
  end
end

This should now render the index.slang from the post directory.

I hope this has helped you in Rendering a different template with a Controller in Amber. And make sure you come and join us in the Amber gitter channel.