Topic: Creating Pop-up menus in Rails
Hi
Apologies if this is a basic question.I am a ruby beginner
What is the best way (or any way) to create a pop-up menu navigation.
I have a set of menu items and for each there will be a set of sub-menu items depending various conditions.
I tried it using remote_function on mouse in and out however though it sort of works works, the sub-menu tend to flicker
I am using the following code:
layouts/_side.rhtml
========================================================================================
<table>
<% @top_actions.each do |toptitle,topcontroller,topaction|%>
<tr onmouseover="<%= remote_function(:url => {:controller => topcontroller,:action =>topaction,:clink => topcontroller})%>"
onmouseout="<%= remote_function(:url => {:controller => topcontroller,:action =>topaction,:clink => 'fade'})%>">
<td align='left' width='99%'><%= toptitle %></td>
<% if topcontroller == params["clink"] %>
<td align="right" width="1%"><%= image_tag "largearrowright.gif" %></td><td align="left" valign="top">
<div id="side_acts"><%= render :partial => "/layouts/side_acts", :object => @side_acts %></div></td>
<%else%>
<td align="right" width="1%"> </td>
<% end %>
</tr>
<% end %>
</table>
==========================================================================
layouts/_side_acts.rhtml
==========================================================================
<div id="action2" class="action2">
<% if params["clink"] %>
<% if @side_acts %>
<table width="100%">
<tr valign="top"><td width="100%">
<% @side_acts.each do |title,controller,action,param|%>
<li><%= link_to title , :controller => controller, :action => action, :id => param %></li>
<% end %>
</td></tr>
</table>
<% end %>
<% end %>
</div>
==============================================================================
and the remote_function will always be side_acts which I put in application_controller
==========
def side_acts
if params["clink"]
clink = params["clink"]
end
if clink == 'fade'
@side_acts = nil
render :update do |page|
page.replace_html 'side_acts', :partial => '/layouts/side_acts' , :object => @side_acts
page.visual_effect(:fade,'side_acts',:duration => 1)
end
return
end
if clink == "login"
@side_acts = [
["sub-menu title x","controller_name","action"],
["sub-menu title x2","controller_name","action2"],
etc ..
]
elsif clink == "something else"
@side_acts = [
["sub-menu title y","temperatures","new","HEX"],
["SBV","temperatures","new","SBV"]
]
elsif clink == "admin"
@side_acts = [
["sub-menu title y","controller_name","action"],
["sub-menu title y2","controller_name","action2"],
etc ..
]
etc etc
if params["clink"]
render :update do |page|
page.replace_html 'side2', :partial => '/layouts/side' , :object => params["clink"]
page.replace_html 'side_acts', :partial => '/layouts/side_acts' , :object => @side_acts
end
end
end
================================================================================
As I mentioned earlier the above works but not well at all , I get flickers when the mouse is on the sub-menu
Any help will be appreciated