我的应用程序控制器中有一个哈希
def search
render layout: "application", template: "search"
@result = { keyOne: "testing the hash", keyTwo: "this is value two" }
end
app / views / search.html.erb
<!-- display hash reults -->
<p>
<%= @result[:keyOne] %>
</p>
我收到错误:nil:NilClass的未定义方法`[]'。我已经尝试了@ result.keyOne,以及其他一些差异,但仍然没有。
请帮助!
答案 0 :(得分:3)
@testing
,但在模板中使用@result
)def search @result = { keyOne: "testing the hash", keyTwo: "this is value two" } render layout: "application", template: "search" end