我正在使用Ruby on Rails的lynda.com教程。创建和使用数组实例变量的第一个实例不起作用。起初我以为@array可能已经成为我使用的新版本的rails 5.0的一个保留字,但是改变它并不会导致“nil”(undefined)错误消失。Ruby轨道不创建实例变量
Ruby Rails 5.0有什么问题?它拒绝定义实例变量并将它们传递给适当的模板。
这是极其恶化的,因为导轨的行为并不如文件记载的那样(即导轨是脑死亡的)。
****************
demo_controller.rb
class DemoController < ApplicationController
def index
render('hello')
end
def hello
@zarray = [1,2,3,4,5] <------------ this is defined
end
def other_hello
render(:text => "Hello EVERYONE!")
end
end
******************
hello.html.erb
<h1>Demo#hello</h1>
<p>Hello World!</p>
<%= 1 + 1 %> <------ works
<% target = "world" %>
</br>
<%= "Hello #{target}" %> <----- works
</br>
<% @zarray.each do |n| %> <---- line 10. Rails claims that @zarray is
not defined
<%= n %></br>
<% end %>
::的ActionView ::模板错误(未定义的方法`每个”近亲:NilClass):
你能给出完整的错误信息吗? – the12