Rails - Changing Boolean In Database From Js.erb File
In my scenario in rails application after sharing content to facebook i will get a response object with post id post_id: 'mypostidhere' If its not successful i will get response o
Solution 1:
current_user
is not a local variable to your JS function/file, it is a helper provided and available in your rails application.
So, what I will like to ask is:
How are you using
current_user
in the JS file?
What you can do is to make an ajax
call to a controller method, and then access current_user
directly from the controller.
Solution 2:
If you want to change the db, you're going to have to communicate with your Rails app, which is done with ajax
:
#app/assets/javascripts/application.js
... // your events will fire
$.ajax({
url: "/users/update",
method: "PUT",
data: { param: "value" }
success: function(data) {
// do something here
};
});
This will allow you to do the following:
#config/routes.rb
resources :usersdo
put :update, on::collectionend#app/controllers/users_controller.rbclassUsersController < ApplicationControllerdefupdate
current_user.update(update_params)
end
private
defupdate_params
params.permit(:param)
endend
Post a Comment for "Rails - Changing Boolean In Database From Js.erb File"