2010-01-06 207 views
-1

我正在開發一個由別人rails專家開發的紅寶石rails項目。我不太瞭解紅寶石。所以,當我修改現有的項目,我無法修復一個錯誤,因爲我不明白幾行代碼。如果有人解釋會很好。這裏有碼 -不明白幾行紅寶石代碼

我家的控制器 - 我的應用程序控制器上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 2010-01-06 12:44:56

+1

這裏有很多東西,你沒有得到什麼? – marcgg 2010-01-06 12:56:58

回答

2

沒有好的參考書,Rails顯得有點難以理解。雖然市場上有很多,但我發現實用書架可以生成一些最好的Ruby和Rails特定書籍(http://www.pragprog.com/titles)。

儘管Ruby比較直觀易懂,但Rails可能需要更長時間才能完全吸收,因爲有許多可能不熟悉的約定。根據你的背景,你可能沒有太多的MVC類型設計經驗,或者一般的面向對象編程經驗,所以這些方面起初可能有些困惑。