ujs

Simple like/unlike button with rails 3, jquery, and ajax

拈花ヽ惹草 提交于 2019-11-27 11:48:07
问题 I have a product, user, and like model. A user can like a product. I am trying to implement a simple like button which, upon a click, allows a user to like a product. Then the like button transforms into an unlike button, allowing the user to unlike a product. Pretty straightforward. I have implemented the model/controller logic for the above. I am not very good with javascript/ajax and was wondering what the best way would be to implement the above functionality. I want the like/unlike

Rails 3 UJS - controller gets called twice by link_to :remote

▼魔方 西西 提交于 2019-11-27 06:44:51
I have a weird problem where JQuery is creating two AJAX requests for a link_to method. I am developing a Rails 3 app with JQuery for UJS. I have a toggle link which toggles between 'Follow' and 'Unfollow' My link is rendered as below: <span id="follow_link"> <a href="/tfollow_artist?id=8103103" data-method="post" data-remote="true" id="follow_artist" rel="nofollow">Unfollow</a> </span> and my controller is setup so: def tfollow_artist @artist = Artist.find(params[:id]) if current_user.following?(@artist) current_user.stop_following(@artist) else current_user.follow(@artist) end end which

Rails 3 UJS - controller gets called twice by link_to :remote

蓝咒 提交于 2019-11-26 12:09:13
问题 I have a weird problem where JQuery is creating two AJAX requests for a link_to method. I am developing a Rails 3 app with JQuery for UJS. I have a toggle link which toggles between \'Follow\' and \'Unfollow\' My link is rendered as below: <span id=\"follow_link\"> <a href=\"/tfollow_artist?id=8103103\" data-method=\"post\" data-remote=\"true\" id=\"follow_artist\" rel=\"nofollow\">Unfollow</a> </span> and my controller is setup so: def tfollow_artist @artist = Artist.find(params[:id]) if