Skip to content

Can't use an array as a view variable #37

@dbackeus

Description

@dbackeus

Though the actual error might be "can't run methods on objects in templates".

# Controller
class MyController < Base::Controller
  actions :index

  view "index", "#{__DIR__}/../views/ragas"
  def index
    @array = [1,2,3]

    render "index"
  end
end

# index.ecr
<%= array.length %>

Error:

Error: instance variable '@array' of MyController was not initialized in all of the 'initialize' methods, rendering it nilable

Though if I just have <%= array %> in the view that compiles and renders just fine...

What's up?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions