Answer the question
In order to leave comments, you need to log in
The form is submitted 2 times, where can I find the error?
Looked at the previous solutions to this problem, but did not find a solution for myself. Locally in development, everything is sent exactly and as it should. I do assets:precompile - the form is sent 2 times, I do assets:clobber => everything works again as intended. After I upload it to production (lokum.ru), the forms are always sent in 2 increments. If you make assets: clobber, then assets will disappear. Is there a solution to this problem?
I don’t know where to look for the error, I also tried rake assets:precompile && rake assets:clobber(clean did it too)
doctype html
html lang="en"
head
meta charset="utf-8" /
meta content="width=device-width, initial-scale=1.0" name="viewport" /
title= content_for?(:title) ? yield(:title) : "
= stylesheet_link_tag "application"
= javascript_include_tag "vendor/modernizr"
= csrf_meta_tags
body
.row
= yield
= javascript_include_tag "application"
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require foundation
//= require turbolinks
//= require jquery.color-2.1.2.min
$(function(){ $(document).foundation(); });
I, [2014-08-11T12:18:22.551991 #14031] INFO -- : Started POST "/projects" for 92.100.79.94 at 2014-08-11 12:18:22 +0400
I, [2014-08-11T12:18:22.554364 #14031] INFO -- : Processing by ProjectsController#create as JS
I, [2014-08-11T12:18:22.554524 #14031] INFO -- : Parameters: {"utf8"=>"", "name"=>"Для проверку"}
I, [2014-08-11T12:18:22.560895 #14031] INFO -- : Rendered projects/_project.html.slim (0.3ms)
I, [2014-08-11T12:18:22.563335 #14031] INFO -- : Rendered projects/create.js.coffee (3.0ms)
I, [2014-08-11T12:18:22.563580 #14031] INFO -- : Completed 200 OK in 9ms (Views: 3.6ms | ActiveRecord: 2.7ms)
I, [2014-08-11T12:18:22.564771 #14031] INFO -- : Started POST "/projects" for 92.100.79.94 at 2014-08-11 12:18:22 +0400
I, [2014-08-11T12:18:22.566380 #14031] INFO -- : Processing by ProjectsController#create as JS
I, [2014-08-11T12:18:22.566446 #14031] INFO -- : Parameters: {"utf8"=>"", "name"=>"Для проверку"}
I, [2014-08-11T12:18:22.572834 #14031] INFO -- : Rendered projects/_project.html.slim (0.3ms)
I, [2014-08-11T12:18:22.574709 #14031] INFO -- : Rendered projects/create.js.coffee (2.4ms)
I, [2014-08-11T12:18:22.574962 #14031] INFO -- : Completed 200 OK in 8ms (Views: 3.0ms | ActiveRecord: 3.0ms)
Answer the question
In order to leave comments, you need to log in
class ProjectsController < ApplicationController
def create
@project = Project.create(name: params[:name])
@projects = Project.all
authorize(@project)
create.js.coffee
<% if @project.valid? %>
$('.tabs li').removeClass 'last'
$('.tabs').append '<li class=\"last\"><%= j(render @project) %></li>'
notice $('.project-<%= @project.id %>'), '#eaeaae'
$('.tabs input').val ''
<% else %>
notice $('.tabs input'), '#ff6666'
$('.tabs input').val ''
$('.tabs input').attr 'placeholder', '<%= @project.errors[:name].first %>'
<% end %>
index.html.slim
ul.tabs
li
= form_tag('/projects', method: :post, remote: true) do
= text_field_tag(:name, nil, placeholder: 'Новый проект')
- @projects.each_with_index do |project, index|
li[class="#{'active' if index == 0}#{' last' if index == @projects.size-1}"]
= render project
It is possible that the submit event handler is duplicated on the form. Can be checked with the jQuery Debugger extension for chrome. I had a similar problem, but only the other way around, in a developer environment (but it did not appear in safari).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question