Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

authentication issue #148

Open
istiaqiut opened this issue Jul 20, 2017 · 4 comments
Open

authentication issue #148

istiaqiut opened this issue Jul 20, 2017 · 4 comments

Comments

@istiaqiut
Copy link

When I submit rating, I got the following errors

Parameters: {"score"=>"4", "dimension"=>"satisfaction", "id"=>"36", "klass"=>"Product"}
Can't verify CSRF token authenticity.
Completed 422 Unprocessable Entity in 1ms (ActiveRecord: 0.0ms)

ActionController::InvalidAuthenticityToken (ActionController::InvalidAuthenticityToken):

@marciotoze
Copy link

If anyone still needs it:

I changed this $.post https://github.com/wazery/ratyrate/blob/master/lib/generators/ratyrate/templates/ratyrate.js.erb#L45-L60

to:

$.ajax({
  type: "POST",
  beforeSend: function(xhr) {xhr.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content'))},
  url: '<%= Rails.application.class.routes.url_helpers.rate_path %>',
  data: {
    score: score,
    dimension: $(this).attr('data-dimension'),
    id: $(this).attr('data-id'),
    klass: $(this).attr('data-classname')
  },
  success: function(data) {
    if(data) {
      if ($(_this).attr('data-disable-after-rate') == 'true') {
        $(_this).raty('set', { readOnly: true, score: score });
      }
    }
  },
});

to send X-CSRF-Token too and works well

@Sandil9
Copy link

Sandil9 commented Jul 22, 2019

How to use above code so that existing gem will work??

@Sandil9
Copy link

Sandil9 commented Jul 22, 2019

@istiaqiut How did you get your problem solved??

@Sandil9
Copy link

Sandil9 commented Jul 22, 2019

I found it... Thanks...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants