This application is built on Ruby on Rails, using Ruby version 2.1.4 and Rails version 4.1.14.
I have a Javascript dropdown menu in the header bar that displays a list of items. However, I'm struggling to figure out how to dynamically change the menu options based on the current page.
For example, the "Item view" page may display a certain set of options, while the "Item Edit" page has a different set of options. The challenge is to have the menu items change dynamically on each page.
The header bar, including the dropdown menu, is a partial that is included in every page before the main content. The menu options themselves need to be dynamic.
My initial approach was to define an array (@menulinks) on each page, specifying the menu items and their respective URLs. For example:
@menulinks = {'Edit' => '/item/edit/', 'Delete' => '/item/delete/' etc etc}
I then intended to pass this array into the UL element that controls the menu in the header bar partial. However, I realized that the links require additional logic, such as calling methods using link_to. For instance, a delete link might look like this:
= link_to "Delete", item_path(@item), method: :delete, data: {confirm: "Are you sure you want to delete this item?"}
My question now is how to properly pass such complex links into the UL element. Is there a way to escape the link part so that Rails can interpret it correctly within the UL?
Alternatively, I wonder if I am overcomplicating the situation and if there is a simpler solution to achieve the dynamic menu options.