0

我正在使用 Foundation 和 Rails(我不知道为什么,但我认为这个问题存在于 Foundation 中)。当我为文章创建新评论时,在第一篇文章上我每次点击都会有一个评论,因为它必须是,但是如果我去另一篇文章 - 它会创建两个类似的评论,去另一篇文章,我得到 4 条评论,然后是 7等等。我认为Foundation中的问题,因为它在浏览器中呈现错误:

未捕获的错误:jquery-ujs 已经加载!和

Object [object Object] 没有方法“基础”

请告诉我如何解决这个问题

我的模型:

class Comment
  include Mongoid::Document
  include Mongoid::Timestamps
  belongs_to :commentable, polymorphic: true
  has_many :answers, as: :commentable, class_name: "Comment"

  default_scope queryable.order_by(:created_at.asc)


  field :body, type: String
  validates_presence_of :body


end

我的控制器动作:

def create
@comment = @commentable.comments.new(params_comment)
if @comment.save
  flash.now[:notice] = "..."
  @response = {comment: @comment, model: @commentable}
  respond_with(@comment) { @response }
else
  flash.now[:alert] = "..."
  respond_with(@comment)
end

结尾

我的 create.js.coffee

$("<%= escape_javascript( render 'shared/comment', @response)%>").appendTo(".comments").hide().fadeIn(500)

和我的观点:

.comments
  =render "comment"

我的部分:

.comment{ id: "comment-#{comment.id}"}
  = image_tag("delete/brian.jpg", class: "avatar")
  .comment-author
    =Faker::Name.name
    %time.comment-date= l comment.created_at
  .comment-text
    = comment.body
  -if comment.answers.any?
    .answers
      -comment.answers.each do |answer|
        .comments-answer
          =image_tag('delete/brian.jpg',class: "avatar")
          .comment-author
            =Faker::Name.name
            %time.comment-date= l(answer.created_at)
          .comment-text= answer.body
        = form_for([comment, Answer.new]) do |f|
          = f.text_area :body, rows: 8
          = f.submit 
  .wrapper
    = link_to 'Destroy', [model, comment], method: :delete, remote: true,class: "euro"
  %hr

形式:

#comment_form
 = form_for([@article, @comment],:remote => true) do |f|
  = f.text_area :body, rows: 8
  = f.submit "Написать", class: "button small round"
4

1 回答 1

0

您可能正在加载两个 jquery 副本,导致这两个错误。Foundation 默认包含它自己的 jQuery 副本。只需删除其中一个,它就会清理干净。

另见:https ://github.com/zurb/foundation/issues/2125

于 2013-10-07T02:20:27.470 回答