In my Rails application, I add a certain user to the reader's list when he views a certain post.
PostsController#Show
@post = Post.find(params[:id])
if (current_user)
@post.reader_links.create(reader_id: current_user.id)
end
However, I want to implement this from the client side, using javascript and ajax request. The feature will be slightly changed so that the user will be added to the list ONLY when he types into a certain form(presses a key).
So the original code will be replaced by the following code in posts/show.erb.html
function typeCatch(){
$(this).off("keypress",typeCatch)//remove handler
//I WANT TO ADD THE USER TO THE LIST AT THIS POINT
}
$("#field_id").on("keypress",typeCatch)
I need some help to implement the original feature in javascript and posting through ajax request. Any help will be greatly appreciated.