[英]Rails: respond_to js do not render with text is a String
I have a code to responde format js 我有一个代码来响应js格式
app = CheckAppExist.new(params[:url])
if(app.exist?)
cookies[:package_name] = app.package_name
cookies[:app_url] = app.app_url
respond_to do |format|
format.html {}
format.json {}
format.js { render :text => "200" }
end
else
respond_to do |format|
format.html {}
format.json {}
format.js { render :text => "Url or Package Name is wrong ", status: :unprocessable_entity }
end
end
Code above is work, but when i change respond text with 上面的代码是可行的,但是当我更改响应文本时
format.js { render :text => "200" }
to format.js { render :text => "some text here" }
format.js { render :text => "200" }
为format.js { render :text => "some text here" }
It don't work. 没用 I use rails ujs to send and receive request. 我使用Rails ujs发送和接收请求。
When is text is a String number("200"), method .on("ajax:success",...)
is run, when text render is String method .on("ajax:error",...)
is run. 当text是字符串数字(“ 200”)时,运行方法.on("ajax:success",...)
,当text渲染为String方法.on("ajax:error",...)
是跑。
I don't understand about above error, anyone can help me. 我不了解上述错误,任何人都可以帮助我。 Tks. 韩国社交协会。
尝试这个:
render inline: 'your text'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.