我正在使用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