jQuery的阿贾克斯+ + Haml的。 js.erb文件没有发射 [英] jQuery + Ajax + Haml. js.erb files not firing

查看:170
本文介绍了jQuery的阿贾克斯+ + Haml的。 js.erb文件没有发射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这几个经验看完了之后,我觉得可能需要再次提出这个问题。编码在Rails3,我想,当用户试图在我的应用程序的另一个元素创建后实施一些光滑的Ajax效果。这里的code,我关心的是:

After reading up on a few experiences, I feel this issue might need to be brought up again. Coding in Rails3, I'm trying to implement some smooth Ajax effects when a user tries to create a post on another element of my app. Here's the code I'm concerned with:

应用/人次/职位/ new.html.haml

- form_for @post, :remote=>true do |f|
    = f.text_area :content
    = submit_tag "Post"

应用程序/控制器/ post_controller.rb

def create
  @comment = Post.new(params[:post])
  @comment.save
end

应用/人次/职位/ create.js.erb:

alert("ajax worked!");

我已经按照我所看到的 UJS Railscast ,但似乎没有任何是射击。不仅如此,但萤火没有给我发生了什么事的任何描述性的证据。它告诉我,它在提交作出新的岗位目标,但没有进一步。

I've followed what I saw on the UJS Railscast, but nothing seems to be firing. Not only that, but firebug fails to give me any descriptive evidence of what's happening. It tells me that it made the new post object upon submission, but nothing further.

任何想法?

推荐答案

我找到了答案!问题是,当控制器被渲染的观点,这是包括我的应用程序的整体布局;布局是屈从于渲染动作,让我的JavaScript code载我.js.erb文件里被吐出到我application.rhtml的。我通过包括我的控制器操作这里面显示我的帖子修复了这个问题:

I found the answer! The issue was that when the controller was rendering the view, it was including the overall layout of my application; the layout was yielding to the rendering action, so my javascript code contained inside of my .js.erb file was spit out into my application.rhtml. I fixed this issue by including this inside of my controller action to display my posts:

respond_to do |format|
  format.js {render :layout=>false}
end

这篇关于jQuery的阿贾克斯+ + Haml的。 js.erb文件没有发射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆