2010-01-06 115 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类型设计经验,或者一般的面向对象编程经验,所以这些方面起初可能有些困惑。