简体   繁体   English

helper_method中的控制器未显示Ruby on Rails视图

[英]Controller in helper_method not showing views Ruby on Rails

I have this view new.html.erb : 我有这个观点new.html.erb

<h1>EVALUATING MODEL PERFORMANCE</h1>
<%= test %>
<%= "#{controller_name}/#{action_name}" %>

The controller is articles_controller.rb : 控制器为articles_controller.rb

class ArticlesController < ApplicationController
    def new
    y = R.pull "capture.output(summary(rnorm(10)))"
    puts y
    end

    helper_method :test
    def test
    sample_size = 10
    R.eval "x <- rnorm(#{sample_size})"
    R.eval "summary(x)"
    R.eval "sd(x)"
    y = R.pull "capture.output(summary(rnorm(10)))"
    puts y
    end
end

Why does the output (shown here: ruby in web ) does not include the results of the test method? 为什么输出(如下所示: web中的ruby )不包含test方法的结果?

you need to return y at the end of your test method. 您需要在test方法的末尾return y puts doesnt actually return anything (it returns nil ), it just prints to the console. puts实际上不返回任何东西(它返回nil ),它只是打印到控制台。 so if puts is the last thing in your method, it will be returned. 因此,如果puts是方法中的最后一件事,它将被返回。 but since it doesnt return anything, there is nothing for your view to display. 但由于它不返回任何内容,因此您的视图没有任何内容可以显示。

by returning y , your view will be able to display the string (though i expect the formatting to be all over the place). 通过返回y ,您的视图将能够显示字符串(尽管我希望格式到处都是)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM