Je travaille sur un projet de rubis sur rails qui est développé par quelqu'un d'autre spécialiste des rails. Je ne connais pas bien ruby. Donc, pendant que je modifiais le projet existant, je ne pouvais pas corriger un bogue parce que je ne comprenais pas le code de quelques lignes. Ce sera génial si quelqu'un explique. Voici les codes -ne comprends pas quelques lignes codes ruby
sur mon contrôleur de la maison - home_controller.rb
class HomeController < ApplicationController
menu_default :overview
menu_specific :contact, :contact
sur mon contrôleur d'application - application.rb
# report the current menu to the application helper, when forming
# tabs
def current_menu
# work out the action of the current request
action = request.path_parameters['action']
# set the default
menu_id = self.class.menu_structure[:default]
# any specific ?
menu_id = self.class.menu_structure[:specifics][action] unless self.class.menu_structure[:specifics].nil? or self.class.menu_structure[:specifics][action].nil?
menu_id
end
def self.menu_default menu_id
# default the menu
@@menu ||= {}
# work out the controller this relates to
self.menu_structure[:default] = menu_id
end
def self.menu_specific menu_id, actions
# turn the actions into an array
actions = [actions] unless actions.is_a?(Array)
# enumerate actions and setup
actions.each do |action|
self.menu_structure[:specifics] ||= {}
self.menu_structure[:specifics][action.to_s] = menu_id
end
end
def self.menu_structure
controller = self.to_s
@@menu ||= {}
end
sur mon assistant d'application - application_helper.rb
# page tab helper
def tab menu_id, title, location
# ask the application controller which is the current location
# form the link with the appropriate class
link = link_to title, location
if(menu_id == controller.current_menu)
content_tag("div", link, :class=>"menu_selected")
else
content_tag("div", link, :class=>"menu_open")
end
end
sur ma mise en page - main.haml
= tab :overview, "Overview", overview_url
Je suis resté pendant des jours. Sil te plait aide moi. Merci
Quel est le bug? Quelle est l'erreur? – rfunduk
Il y a beaucoup de choses qui se passent ici, qu'est-ce que tu n'as pas? – marcgg