Note that there are some explanatory texts on larger screens.

plurals
  1. POCreating items via ajax force rails to create additional items in DB
    text
    copied!<p>I am using Foundation and Rails (I dont know why, but I think that problem in foundation). When I create new comment for article, on first article I have one comment per click, as it have to be, but if I go to another article - its creates two similar comments, go to another article and I get 4 comments, then 7 and so on. I think that problem in Foundation, because it render errors in Browser:</p> <p>Uncaught Error: jquery-ujs has already been loaded! and</p> <p>Object [object Object] has no method 'foundation' </p> <p>Tell me please how can I solve this problem</p> <p>my model:</p> <pre><code>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 </code></pre> <p>my controller action: </p> <pre><code>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 </code></pre> <p>end</p> <p>my create.js.coffee</p> <pre><code>$("&lt;%= escape_javascript( render 'shared/comment', @response)%&gt;").appendTo(".comments").hide().fadeIn(500) </code></pre> <p>and my view:</p> <pre><code>.comments =render "comment" </code></pre> <p>my partial:</p> <pre><code>.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 </code></pre> <p>form: </p> <pre><code>#comment_form = form_for([@article, @comment],:remote =&gt; true) do |f| = f.text_area :body, rows: 8 = f.submit "Написать", class: "button small round" </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload