我想我说的是这个问题的标题,但这是问题所在:
我的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
将响应放入视图中的正确方法是什么?
您需要将该值分配给实例变量(通过@
在名称之前添加),以便其持久存在于视图中:
@response_count = response["count"]
然后在视图中可以像这样打印它:
<%= @response_count %>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句