0

この質問のタイトルを正しく述べたと思いますが、これが問題です:

私の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_countを調査ビューに入れることだけです。必要ないかもしれませんがSurvey.create(y: response_count)、これはこれを機能させるための私の試みの1つでした。基本的に、これをビューに書きたいだけです:

puts response_count

その応答をビューに入れる適切な方法は何ですか?

4

1 に答える 1

0

@ビューに永続化されるように、値をインスタンス変数に割り当てる必要があります (名前の前に追加することにより)。

@response_count = response["count"]

次に、ビューで次のように印刷できます。

<%= @response_count %>
于 2013-08-11T00:03:15.430 に答える