2010-08-09 69 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 %> 

希望这有助于!