我想我正确地说明了这个问题的标题,但这就是问题所在:
我的 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)
,但这是我尝试让它发挥作用的一部分。本质上,我只想在一个视图中写这个:
puts response_count
将响应放入视图的正确方法是什么?