[英]Ruby on Rails 2.3, form_tag submitted to Rails controller, JS function not called
Current setup: Ruby on Rails 2.3 with Ruby 1.8.7 (don't ask...we're working on it). 当前设置:Ruby on Rails 2.3和Ruby 1.8.7(不要问...我们正在努力)。
form_tag helper is used in a Bootstrap modal to call action in Rails controller. 在引导程序模式中使用form_tag helper来调用Rails控制器中的操作。 Here's the view (.haml) 这是视图(.haml)
- form_tag({:action => 'update_logins'},
{:method => :post, :multipart => true, :id => 'upload_form', :target => 'upload_target', :class=>'form-horizontal' })
The controller action is properly called, but I am returning a call to a Javascript function, and despite numerous attempts, it is not calling the function, but instead appears to be rendering text. 控制器动作已正确调用,但是我正在返回对Javascript函数的调用,尽管进行了多次尝试,但它没有调用该函数,而是呈现了文本。 Even a simple render statement in the controller doesn't work: render :js => "alert('hello');"
甚至控制器中的一个简单的render语句也不起作用: render :js => "alert('hello');"
I have a feeling this has to do with how the request header doesn't seem to accept javascript: 我觉得这与请求标头似乎不接受javascript有关:
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
The response header indicates Javascript: Content-Type:text/javascript; charset=utf-8
响应标头指示Javascript: Content-Type:text/javascript; charset=utf-8
Content-Type:text/javascript; charset=utf-8
And the response is received properly: alert('hello');
并正确接收到响应: alert('hello');
But no success in getting it to actually call any functions. 但是实际上无法成功调用任何函数。
Any ideas? 有任何想法吗?
I assume you are using SLIM/HAML for templating engine. 我假设您正在使用SLIM / HAML来模板化引擎。 check if you are generating a <form>
tag in your HTML 检查您是否在HTML中生成<form>
标记
you can try replacing 你可以尝试更换
- form_tag({:action => 'update_logins'},{:method => :post, :multipart => true, :id => 'upload_form', :target => 'upload_target', :class=>'form-horizontal' })
to 至
= form_tag({:action => 'update_logins'},{:method => :post, :multipart => true, :id => 'upload_form', :target => 'upload_target', :class=>'form-horizontal' })
this way, it will create a <form>
in your html. 这样,它将在您的html中创建一个<form>
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.