Ruby-on-rails 如何在 Rails 控制台内为 Rails 2.x 和 3.x 使用所有视图和辅助方法?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4112050/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 23:33:46  来源:igfitidea点击:

How to use all view and helper methods inside of Rails console for Rails 2.x and 3.x?

ruby-on-railsruby-on-rails-3

提问by nonopolarity

helper.method_nameworked in some version of Rails... are there ways that work in both Rails 2.2.2, 2.3.5, and 3.0.1? (to use all view and helper methods)

helper.method_name在某些版本的 Rails 中工作......是否有在 Rails 2.2.2、2.3.5 和 3.0.1 中工作的方法?(使用所有视图和辅助方法)

回答by Nicolas Blanco

You can also try :

您也可以尝试:

YourController.helpers.my_helper

for example :

例如 :

> ApplicationController.helpers.content_tag(:div, "test")
=> "<div>test</div>" 

This works with Rails 2 and Rails 3.

这适用于 Rails 2 和 Rails 3。

回答by nonopolarity

please try to this

请试试这个

rails console
helper.any_method_of_helper(pass_argument)

example

例子

helper.number_to_currency('123.45')