end
# Subscribe user to diary comments
- @diary_entry.subscribers << @user
+ @diary_entry.subscriptions.create(user: @user)
redirect_to :controller => "diary_entry", :action => "list", :display_name => @user.display_name
else
end
# Add the commenter to the subscribers if necessary
- @entry.subscribers << @user unless @entry.subscribers.exists?(@user.id)
+ @entry.subscriptions.create(user: @user) unless @entry.subscribers.exists?(@user)
redirect_to :controller => "diary_entry", :action => "view", :display_name => @entry.user.display_name, :id => @entry.id
else
def subscribe
diary_entry = DiaryEntry.find(params[:id])
- if ! diary_entry.subscribers.exists?(@user.id)
- diary_entry.subscribers << @user
- end
+ diary_entry.subscriptions.create(user: @user) unless diary_entry.subscribers.exists?(@user)
redirect_to :controller => "diary_entry", :action => "view", :display_name => diary_entry.user.display_name, :id => diary_entry.id
rescue ActiveRecord::RecordNotFound
def unsubscribe
diary_entry = DiaryEntry.find(params[:id])
- if diary_entry.subscribers.exists?(@user.id)
- diary_entry.subscribers.delete(@user)
- end
+ diary_entry.subscriptions.where(user: @user).delete_all if diary_entry.subscribers.exists?(@user)
redirect_to :controller => "diary_entry", :action => "view", :display_name => diary_entry.user.display_name, :id => diary_entry.id
rescue ActiveRecord::RecordNotFound