Rails 新操作在 AJAX GET 上不返回 HTML
我正在开发一个项目,将 Rails gem 从 2.3.5 升级到 2.3.11,现在我无法让控制器操作通过 jQuery ajax get 返回 HTML。例如,当我运行此 javascript 时: $(function(){ $.get("/inbox/new"); });
我可以在 Firebug 中看到收到的请求状态为200. 我可以在我的日志中看到正在呈现的请求。我可以看到 CSRF 令牌在 ajax get 中传递(但我不知道为什么它很重要,因为它是 get 而不是 post)。
我尝试了响应阻止 respond_to do |格式| format.html {渲染:布局=>假,:动作=> :新的} ;
我可以让控制器操作返回任何内容(再次通过 Firebug 确认)的唯一方法是使用 render :text => 控制器操作中的“whatever”
。
有什么想法吗? Rails 2.3.11 中是否有我遗漏的不同内容?
I'm working on a project where I upgraded the rails gem from 2.3.5 to 2.3.11 now I can't get the controller actions to return HTML via jQuery ajax get. For example when I run this javascript: $(function(){ $.get("/inbox/new"); });
I can see in Firebug that the request was received with a status of 200. I can see the request being rendered in my log. I can see that the CSRF token is being passed in the ajax get (but I don't know why it would matter anyways since it's a get and not a post).
I tried the respond to blockrespond_to do |format|
format.html {render :layout => false, :action => :new}
end
The only way I can get the controller action to return anything (once again confirmed via Firebug) is by using render :text => "whatever"
in the controller action.
Any ideas?! Is there something different in rails 2.3.11 that I'm missing?!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想通了。一行很小但很重要的代码把我搞砸了。 new.html.haml 视图中有一个 content_for 块。因此,视图在 AJAX GET 上呈现,但内容未呈现,因为没有指定布局。我不敢相信我在这上面花了那么多时间。令人羞愧的经历。
我至少可以为我失去的许多生产力时间获得一些选票吗?
I figured it out. A very small but significant line of code screwed me up. There was a content_for block in the new.html.haml view. So view rendered on AJAX GET but the content didn't render because there was no layout specified. I can't believe I spent as many hours on this as I did. Humbling experience.
Could I at least get some votes for my many lost hours of productivity?