Dynamic menu calling basic ajax area

i was thinking, that for alot of my application, when i have a record, i
want a menu with all the related ajax calls linked to a that record.
there might me a gem to do this, or an easier way, but this is what i
did. i am open to new ideas, as this was made to work easily from any
view by calling a partial and setting up the ajax info in the helpers.
what do you all think about this type of DRY? is there another better
way? i got it working on link_to but now working on link_to_remote.

views>layout>_menu.rhtml

<%= stylesheet_link_tag ‘ajaxmenu’ %>

GET RELATED INFORMATION
<% makemenu %>

<% @menu.each do |menudetails| %>

    <li>
        <%= link_to_remote menudetails[:name],
        :update => 'ajaxarea',
        :url => { :controller => menudetails[:link_controller],

:action => menudetails[:link_action] },
:before => “$(‘waiting’).show()”,
:success => “$(‘div_part’).visualeffect(‘highlight’)”,
:failure => “alert(‘There was a failure, GOOFY!.’)”,
:complete => “$(‘waiting’).hide()”
%>

<% end %>

WORK IN PROGRESS…HOLD ON,
SHUT UP, AND SIT DOWN!

So you want a different menu for different objects in your system?

May I recommend using different layouts for the different objects. Say
you
have a CandyBarsController, just define:

class CandyBarsController < ApplicationController
layout ‘candy_bars’
end

I think that you might not even have to define the layout if the
controller
name is the same as the layout name, but I’m not sure on that :slight_smile:

On Dec 20, 2007 1:29 PM, gemblon (t.b.)
[email protected]
wrote:

<% makemenu %>
:failure => “alert(‘There was a failure, GOOFY!.’)”,

-- Posted via http://www.ruby-forum.com/.


Ryan B.
http://www.frozenplague.net

Ryan B. wrote:

So you want a different menu for different objects in your system?

May I recommend using different layouts for the different objects. Say
you
have a CandyBarsController, just define:

class CandyBarsController < ApplicationController
layout ‘candy_bars’
end

I think that you might not even have to define the layout if the
controller
name is the same as the layout name, but I’m not sure on that :slight_smile:


Ryan B.
http://www.frozenplague.net

hi ryan,

well, you are a lot smarter then me, so i might not be doing this right.
in each controller, i already have a layout template, that is pretty
complex.
i need to use that.

so, when i edit or show a record, i was gonna display the table data,
and then, under that, show the menu for remote links.

is that not good?

Ryan B. wrote:

Are you able to give me an example of what these remote links are?

oops, sorry ryan… the helper file has:

def makemenu
@menu = []

    #an ajax menu
    item = {
      :name => "Notes",
      :link_controller => "casefilenote",
      :link_action => "list"
      }
    @menu << item

    #an ajax menu
    item = {
      :name => "Case Events",
      :link_controller => "event",
      :link_action => "list"
      }
    @menu << item

end

it all seems to work nice, and is really fast to add ajax menu items.
well, for my application. you just have to watch with layout you use in
a controller, depending on what method is going to be called.

is there a better way?

Are you able to give me an example of what these remote links are?

On Dec 20, 2007 1:51 PM, gemblon (t.b.)
[email protected]
wrote:

end


Posted via http://www.ruby-forum.com/.


Ryan B.
http://www.frozenplague.net

gemblon (t.b.) wrote:

Ryan B. wrote:

and i need to track what menu was selected. so i can gray the menu
background. and fix up a few more things.

i am installing in several places, and i will update it tomorrow if you
want to see it in action. it is not perfectly clean yet, but that is
just me doing some clean up.

:slight_smile:

if you have another idea, let me know. i will try it on a table.

:slight_smile:

We use something here to select which menu item is selected. I can’t
show
you the exact code, but basically you give the containing element of the
link a class depending on an argument passed in.

def menu_selected(menu_item)
if menu_item == “edit” && params[:action] == “edit”
“selected”
end

Then on your menu:

  • Edit
  • ...

On Dec 20, 2007 2:24 PM, gemblon (t.b.)
[email protected]
wrote:

just me doing some clean up.


Ryan B.
http://www.frozenplague.net

Ryan B. wrote:

We use something here to select which menu item is selected. I can’t
show
you the exact code, but basically you give the containing element of the
link a class depending on an argument passed in.

def menu_selected(menu_item)
if menu_item == “edit” && params[:action] == “edit”
“selected”
end

Then on your menu:

  • Edit
  • ...

On Dec 20, 2007 2:24 PM, gemblon (t.b.)
[email protected]
wrote:

just me doing some clean up.


Ryan B.
http://www.frozenplague.net

hey ryan, that seems like a cool idea.
i am gonna give it a try tomorrow.

:slight_smile:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs