Ruby on rails 如何从ViewRails 4.0调用控制器方法

Ruby on rails 如何从ViewRails 4.0调用控制器方法,ruby-on-rails,api,view,controller,Ruby On Rails,Api,View,Controller,我想我把这个问题的标题说对了,但问题是: 我的SurveysController中有以下内容- def pull_responses call= "/api/v2/surveys/" auth = {:username => "test", :password => "password"} url = HTTParty.get("https://fluidsurveys.com#{call}", :basic_

我想我把这个问题的标题说对了,但问题是:

我的SurveysController中有以下内容-

  def pull_responses
    call= "/api/v2/surveys/"
    auth = {:username => "test", :password => "password"}
    url = HTTParty.get("https://fluidsurveys.com#{call}",
                       :basic_auth => auth,
                       :headers => { 'ContentType' => 'application/json' } )
    response = JSON.parse(url.body)
    survey_ids = response["surveys"].map { |s| s["id"] }

    survey_ids.each do |x|

      call= "/api/v2/surveys/#{x}/responses/?_completed=1"
      auth = {:username => "test", :password => "password"}
      url = HTTParty.get("https://Fluidsurveys.com#{call}",
                         :basic_auth => auth,
                         :headers => { 'ContentType' => 'application/json' } )

      response = JSON.parse(url.body)
      response_count = response["count"]
      Survey.create(y: response_count)
    end
  end
  helper_method :pull_responses
我只是想把变量
response\u count
放在我的调查视图中。我可能不需要
调查。创建(y:response\u count)
,但这是我试图让它发挥作用的一次尝试。本质上,我只想从一个角度来写:

put响应\u计数


将该响应放入视图的正确方法是什么?

您需要将该值分配给实例变量(通过在名称之前添加
@
),以便将其保留到视图中:

@response_count = response["count"]
然后在视图中,您可以这样打印:

<%= @response_count %>