我正在尝试制作一个简单的嵌套动态菜单,其中的子类别将根据我在类别中选择的内容来显示子类别。但为了简单起见,我只想在子类别中呈现相同的东西,无论我选择"Home“还是"Job”(主要是文本"show the same“将呈现)
在index.rhtml中,我有这样的功能
<html>
<head>
<%= javascript_include_tag :defaults %>
</head>
<body>
<select id="categories" name="categories">
<option value="1">Home</option>
<option value="2">Job</option>
</select>
<%= observe_field "categories", :update => "subcategories",
:url => { :controller => "hello", :action => "getsubcategories" } %>
<select id="subcategories" name="subcategories">
<option>
</option>
</select>
</bod>
</html>
对于控制器,我有这个
class HelloController < ApplicationController
def index
end
def getsubcategories
puts "Got inside the controller"
end
end
而对于getsubcategories.rhtml,只有一行代码
<option value="<%= subcategory.id %>"><%= "show the same" %>
它显示了一个错误,指向layout.erb,无法在子类别菜单上正确呈现。我意识到最有可能的错误是在getsubcategories.rhtml中,但我尝试了几种不同的方法,仍然是同一个错误。
我该如何解决这个问题呢?感谢您的指导
发布于 2010-10-18 08:31:54
您需要停用此操作的布局
def getsubcategories
render :getsubcategories, :layout => false
end
https://stackoverflow.com/questions/3955725
复制