You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have an issue with the csrf token being expired when submitting a remote form. Here is the code i'm using:
= simple_form_for :user, url: login_path, remote: true, :html=> { class: 'margin-bottom-15' } do |f|
= f.input :email, wrapper: :vertical_input_group, required: true do
= f.email_field :email, class: "form-control", placeholder: 'Enter your email address'
= f.input :password, wrapper: :vertical_input_group, required: true do
= f.password_field :password, class: "form-control", placeholder: 'Enter your password'.row.col-md-12button.btn.btn-special.btn-success.btn-block.btn-lgtype="submit" Sign In
This forms submits the data and then i return in a flash a message plus a link with the method post:
link=view_context.link_to'Resend confirmation email',resend_confirmation_url(email: user_params[:email]),method: :postifuser_params[:email].present?flash[:alert]="Your credentials are wrong or your email is not confirmed. #{link}".html_safe
The link is displayed in the page and then when the user clicks that the link uses the old meta authenticity token so i get an invalid exception.
The application.html file looks ~ like this:
doctype html
htmllang="en"head
= display_meta_tags/ add custom header elements with this
= yield(:head)
= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true
= csrf_meta_tagsbodyclass="#{@body_class}".global-wrapper.container/ show errors in the page or info.unobtrusive-flash-container.container.content-container
= yield
= javascript_include_tag 'application', 'data-turbolinks-eval' => false
# in application_controller.rb# callback to set CSRF TOKEN for non-idempotent ajax requestafter_action:add_csrf_token_to_json_request_headerprivatedefadd_csrf_token_to_json_request_headerifrequest.xhr? && !request.get? && protect_against_forgery?response.headers['X-CSRF-Token']=form_authenticity_tokenendend
// in my js file$(document).ajaxComplete(function(event,xhr,settings){header_token=xhr.getResponseHeader('X-CSRF-Token');csrfTokenif(header_token)$('meta[name=csrf-token]').attr('content',header_token)});
The text was updated successfully, but these errors were encountered:
I have an issue with the csrf token being expired when submitting a remote form. Here is the code i'm using:
This forms submits the data and then i return in a flash a message plus a link with the method post:
The link is displayed in the page and then when the user clicks that the link uses the old meta authenticity token so i get an invalid exception.
The application.html file looks ~ like this:
The application.js file:
I'm using:
The solution i'm using currently to fix this is:
The text was updated successfully, but these errors were encountered: