-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't use an array as a view variable #37
Comments
@dbackeus, What's up is that you can do something like this: # Controller
class MyController < Base::Controller
actions :index
@array = [] of Int32
view "index", "#{__DIR__}/../views/ragas"
def index
@array = [1,2,3]
render "index"
end
end
# index.ecr
<%= array.length %> This should work as |
Thanks for the help, I can compile and render now :) Hope there will be a work around or cleaner solution for this in the future. |
In rails it's discouraged using instance variables in views. I would like to see solution similar to Decent Exposure |
Though avoiding instance vars in rails is hardly an accepted best practice. I do agree that something like decent exposure or simply passing the objects down via the render method would be nicer than having to declare instance variables to avoid the nil issue. |
Though the actual error might be "can't run methods on objects in templates".
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?
The text was updated successfully, but these errors were encountered: