Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 用于动态菜单的菜单字段_Ruby On Rails - Fatal编程技术网

Ruby on rails 用于动态菜单的菜单字段

Ruby on rails 用于动态菜单的菜单字段,ruby-on-rails,Ruby On Rails,我试图制作一个简单的嵌套动态菜单,其中子类别将根据我在类别中选择的内容显示。但为了简单起见,我只想在子类别中呈现相同的内容,无论我选择“Home”还是“Job”(主要是呈现“show the same”的文本) 在index.rhtml中,我有这个 <html> <head> <%= javascript_include_tag :defaults %> </head> <body> <select id="cat

我试图制作一个简单的嵌套动态菜单,其中子类别将根据我在类别中选择的内容显示。但为了简单起见,我只想在子类别中呈现相同的内容,无论我选择“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

家
工作
“子类别”,
:url=>{:controller=>“hello”,:action=>“getsubcategories”}%>
对于控制器,我有这个

<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
class HelloController
对于getsubcategories.rhtml,只有一行

   <option value="<%= subcategory.id %>"><%= "show the same" %>

它显示指向layout.erb的错误,该错误无法在“子类别”菜单上正确渲染。我承认最有可能的错误是在getsubcategories.rhtml中,但我尝试了几种不同的方法,仍然是相同的错误


我怎样才能解决这个问题?感谢您提供的任何指导

您需要取消激活此操作的布局

def getsubcategories
  render :getsubcategories, :layout => false
end

啊,谢谢!!我还有一个问题,是否可以使用第一个表中的特定参数来更新第二个select表。例如,select table 1(来自数据库)有一个键值链接到select table 2(同样来自数据库)。我从选择表1中选择了1个选项,在选择表2中,将只显示数据库中与选择表1键相同的选项?如果我的答案是正确的,请投票并接受它。如果你还有问题的话。提出了一个新问题。