2010-08-09 73 views

回答

5

只需調用它。

如果是在一個不同的輔助文件,您的控制器可以通過使用控制器的方法「helper

添加包括其他幫助文件:

下面是一個例子:

# in the view 
<%= my_helper %> 

# in the helper file 
def my_helper 
    "<div>" + someother_helper_which_generates_html + "</div>" 
end 

**請詳細信息添加到您的問題,如果這是沒有幫助....

15

嘗試:
包括AnotherHelper

1

像這樣的東西應該幫助你(比如,在application_helper.rb)

module ApplicationHelper 

    def create_div 
    html("this is some content") 
    end 

    def html(content) 
    "<div>#{content}</div>" 
    end 

end 

在這種情況下,create_div方法調用帶有字符串參數的HTML方法。 html方法返回一個HTML字符串,其中包含您提供的參數。在一個視圖中,它看起來像:

<%= create_div %> 

希望這有助於!