Search code examples
javascriptruby-on-railsujs

To Ruby on Rails - authenticity_token does not work



I'm a beginner programmer on Ruby on Rails.
I have a form that adds an object with attached. The file is stored on the cloud from Amazon S3.
Form done through javascript using ujs. In the form of added parameter: remote: true. But saving does not occur, and there is an error:
Missing template cards/create, application/create with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :coffee, :slim]}.
Help what to do?

my form:

  = simple_form_for [@deck, @card], remote: true, authenticity_token: true do |f|
    p
      = f.input :original_text, as: :string, label: 'Original text', input_html: { class: 'form-control' }
    p
      = f.input :translated_text, as: :string, label: 'Translated text', input_html: { class: 'form-control' }
    p
      = f.file_field :picture
    p
      = f.button :submit, data: { disable_with: 'Сохраняется...' }, class: "btn btn-success btn-lg btn-block", id: "btn-login"



my new.js.erb:

$("#modal-window").html("<%= j render 'cards/new' %>");



my create.js.erb:

$("#modal-window").modal("hide");
$(".cards-index").html('<%= j render 'cards/all', cards: @cards %>');
$("#card_title").val('');

Solution

  • Great! Problem solved.
    Added gem 'remotipart'
    2 Added to the file application.js after //= require jquery_ujs string //= require jquery.remotipart
    3 Added to the form string authenticity_token: true