views:

16

answers:

1

Hi,

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>
</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

A: 

You need desactivate the layout to this action

def getsubcategories
  render :getsubcategories, :layout => false
end
shingara
ah thank you! I have another question, is it possible to update the second select table by using a certain parameters from the first table. Example, select table 1 (from database) has a key value linked to select table 2 (again from database). I selected 1 option from select table 1, and in select table 2, will just show option from the database that has the same key with select table 1?
heike
If my answer is good upvote it and accept it. If you have another question. Made a new question.
shingara
yes. thank you.
heike