Declare type of instance variable on controller

You don't have to use instance variable here. Local variable is a way Amber app uses by default (and they are accessible in views):

class CompanyController < ApplicationController
  def index
    companies = Company.all
    render("index.slang")
  end
end

But if you want to use an instance variable due to some reason, you need to declare and initialize it at a class level or follow other type inference rules.


As mentioned using a local variable here is the most elegant solution. For people ending up here with a similar error message but in a different context, read below:

The second error message already points to the right solution, the following code should work too:

class CompanyController < ApplicationController
  @companies : Array(Company)?

  def index
    @companies = Company.all
    render("index.slang")
  end
end