-1
나는 다른 누군가가 레일 전문가가 개발 한 레일 프로젝트의 루비 작업을하고있다. 나는 루비를 잘 모른다. 따라서 기존 프로젝트를 수정하는 동안 몇 줄의 코드를 이해할 수 없었기 때문에 버그를 수정할 수 없었습니다. 누군가 설명하면 좋을 것입니다. 내 집 컨트롤러몇 줄의 루비 코드를 모르겠다
- - 내 응용 프로그램 컨트롤러 home_controller.rb
class HomeController < ApplicationController
menu_default :overview
menu_specific :contact, :contact
- 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
- 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
내 레이아웃에 - main.haml
= tab :overview, "Overview", overview_url
며칠 동안 붙어 있습니다. 제발 도와주세요. 감사합니다.
무엇이 버그입니까? 오류가 무엇입니까? – rfunduk
여기에 많은 것들이 있습니다. 당신은 무엇을 얻지 못합니까? – marcgg