Add followable specific notices to follows controller actions and render notice on AJAX JS response.
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
App.Followable =
|
||||
|
||||
update: (followable_id, button) ->
|
||||
update: (followable_id, button, notice) ->
|
||||
$("#" + followable_id + " .js-follow").html(button)
|
||||
if ($('[data-alert]').length > 0)
|
||||
$('[data-alert]').replaceWith(notice)
|
||||
else
|
||||
$("body").append(notice)
|
||||
|
||||
@@ -5,12 +5,14 @@ class FollowsController < ApplicationController
|
||||
def create
|
||||
followable = find_followable
|
||||
@follow = Follow.create(user: current_user, followable: followable)
|
||||
flash.now[:notice] = t("shared.followable.#{followable_translation_key(@follow.followable)}.create.notice_html")
|
||||
render :refresh_follow_button
|
||||
end
|
||||
|
||||
def destroy
|
||||
@follow = Follow.find(params[:id])
|
||||
@follow.destroy
|
||||
flash.now[:notice] = t("shared.followable.#{followable_translation_key(@follow.followable)}.destroy.notice_html")
|
||||
render :refresh_follow_button
|
||||
end
|
||||
|
||||
@@ -20,4 +22,8 @@ class FollowsController < ApplicationController
|
||||
params[:followable_type].constantize.find(params[:followable_id])
|
||||
end
|
||||
|
||||
def followable_translation_key(followable)
|
||||
followable.class.name.parameterize.gsub("-", "_")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
App.Followable.update("<%= dom_id(@follow.followable) %>",
|
||||
"<%= j render('follow_button', follow: @follow) %>")
|
||||
"<%= j render('follow_button', follow: @follow) %>",
|
||||
"<%= j render('layouts/flash') %>")
|
||||
|
||||
Reference in New Issue
Block a user