2010-01-06 6 views
-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 

며칠 동안 붙어 있습니다. 제발 도와주세요. 감사합니다.

+3

무엇이 버그입니까? 오류가 무엇입니까? – rfunduk

+1

여기에 많은 것들이 있습니다. 당신은 무엇을 얻지 못합니까? – marcgg

답변

2

레일은 좋은 참고서가 없으면 다소 꿰 뚫을 수 있습니다. 시장에 많은 것들이 있지만, 나는 Pragmatic Bookshelf가 Ruby와 Rails에 적합한 Ruby and Rails 특정 제품 (http://www.pragprog.com/titles)을 발견했다.

Ruby는 이해하기가 쉽지만 익숙하지 않은 규칙이 있으므로 Rails를 완전히 흡수하는 데 오래 걸릴 수 있습니다. 배경에 따라, MVC 타입 디자인이나 객체 지향 프로그래밍에 익숙하지 않았을 수도 있습니다. 따라서 처음에는 다소 어리둥절해질 수 있습니다.

관련 문제