prograils / lit

rails i18n web interface
MIT License
298 stars 71 forks source link

On-site live translations does not update #177

Closed christianmeichtry closed 2 years ago

christianmeichtry commented 3 years ago

When the frontend value gets send, the CSRF token is not valid

Started PATCH "/lit/localization_keys/387/localizations/1151" for 78.155.22.58 at 2021-05-18 15:14:51 +0200
Cannot render console from 78.155.22.58! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Processing by Lit::LocalizationsController#update as JSON
  Parameters: {"localization"=>{"translated_value"=>"<font color=\"#dc3545\">Tous</font><br>"}, "localization_key_id"=>"387", "id"=>"1151"}
Can't verify CSRF token authenticity.
Completed 422 Unprocessable Entity in 0ms (ActiveRecord: 0.0ms)

ActionController::InvalidAuthenticityToken (ActionController::InvalidAuthenticityToken):
mlitwiniuk commented 3 years ago

@christianmeichtry in order for this to work both jquery and rails_ujs needs to be installed and initialized. Everything works fine in sample app (Rails 6.1) with following content of app/javascript/packs/application.js:

import Rails from "@rails/ujs"
import Turbolinks from "turbolinks"
import * as ActiveStorage from "@rails/activestorage"
import "channels"

Rails.start()
Turbolinks.start()
ActiveStorage.start()

and webpack configuration (in config/webpack/environment.js)

const { environment } = require('@rails/webpacker')

const webpack = require('webpack')
environment.plugins.prepend('Provide',
  new webpack.ProvidePlugin({
    $: 'jquery/src/jquery',
    jQuery: 'jquery/src/jquery'
  })
)
module.exports = environment

Most likely at least jquery dependency should be removed, but that's out of current scope.