jquery - Creating items via ajax force rails to create additional items in DB -
i using foundation , rails (i dont know why, think problem in foundation). when create new comment article, on first article have 1 comment per click, have be, if go article - creates 2 similar comments, go article , 4 comments, 7 , on. think problem in foundation, because render errors in browser:
uncaught error: jquery-ujs has been loaded! and
object [object object] has no method 'foundation'
tell me please how can solve problem
my model:
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
my controller action:
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
end
my create.js.coffee
$("<%= escape_javascript( render 'shared/comment', @response)%>").appendto(".comments").hide().fadein(500)
and view:
.comments =render "comment"
my partial:
.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 |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]) |f| = f.text_area :body, rows: 8 = f.submit .wrapper = link_to 'destroy', [model, comment], method: :delete, remote: true,class: "euro" %hr
form:
#comment_form = form_for([@article, @comment],:remote => true) |f| = f.text_area :body, rows: 8 = f.submit "Написать", class: "button small round"
you loading 2 copies of jquery causing both of these errors. foundation includes it's own copy of jquery default. remove 1 of them, , should clear up.
Comments
Post a Comment