开发者

rails observe_fields for dynamic menus

I am trying to make a simple nested dynamic menus, where subcategories will be shown based on what I choosed in category. But to make it very simple, I just wanted to render the same thing in the subcategory, whether I choosed "Home" or "Job" (mainly a text of "show the same" will be rendered)

In index.rhtml I have this

<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>
<开发者_JAVA百科;/select>

</bod>
</html>

For controller, I have this

class HelloController < ApplicationController

def index
end

def getsubcategories
    puts "Got inside the controller"
end  

end

and for getsubcategories.rhtml, there is only 1 line

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

It shows an error that points to layout.erb, that can not render correctly on the subcategories menu. I recogn that most likely the mistake is in getsubcategories.rhtml, but I tried several different ways, and still the same error.

How can I fix this? Thank you for any guidance


You need desactivate the layout to this action

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜