-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed the add_error to work with js call
- Loading branch information
Showing
1 changed file
with
33 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,50 @@ | ||
class Api::V1::ErrorsController < Api::V1::ApiController | ||
skip_before_action :authenticate_member!, except: [:index, :show, :update, :notify_subscribers] | ||
skip_before_action :authenticate_member!, except: [:index, :show, :update, :notify_subscribers] | ||
|
||
def index | ||
@errors = current_site.issues | ||
end | ||
def index | ||
@errors = current_site.issues | ||
end | ||
|
||
def create | ||
# subscriber = current_site.subscribers.create_with(name: error_params[:name]).find_or_create_by!(email: error_params[:email]) | ||
# @error = current_site.issues.create_with(description: 'etcdasdasadsad').find_or_create_by(page_title: error_params[:page_title]) | ||
def create | ||
# subscriber = current_site.subscribers.create_with(name: error_params[:name]).find_or_create_by!(email: error_params[:email]) | ||
# @error = current_site.issues.create_with(description: 'etcdasdasadsad').find_or_create_by(page_title: error_params[:page_title]) | ||
# @error.increment!(:occurrences) | ||
|
||
# SubscriberIssue.create_with(issue_id: @error.id).find_or_create_by(subscriber_id: subscriber.id) | ||
# message = Message.create(content: error_params['message'], issue_id: @error.id) | ||
end | ||
# SubscriberIssue.create_with(issue_id: @error.id).find_or_create_by(subscriber_id: subscriber.id) | ||
# message = Message.create(content: error_params['message'], issue_id: @error.id) | ||
end | ||
|
||
def show | ||
@error = current_site.issues.where('issues.id = ?', params[:id]).first | ||
end | ||
def show | ||
@error = current_site.issues.where('issues.id = ?', params[:id]).first | ||
end | ||
|
||
def update | ||
@error = Issue.find(params[:id]) | ||
@error.update_attributes(error_params) | ||
end | ||
def update | ||
@error = Issue.find(params[:id]) | ||
@error.update_attributes(error_params) | ||
end | ||
|
||
def notify_subscribers | ||
@error = Issue.find(params[:id]) | ||
@message = params[:message] | ||
@error.subscribers.each do |member| | ||
UserMailer.notify_subscriber(@error, member, @message).deliver_now | ||
end | ||
end | ||
def notify_subscribers | ||
@error = Issue.find(params[:id]) | ||
@message = params[:message] | ||
@error.subscribers.each do |member| | ||
UserMailer.notify_subscriber(@error, member, @message).deliver_now | ||
end | ||
end | ||
|
||
def add_error | ||
error_params | ||
subscriber = current_site.subscribers.create_with(name: "test").find_or_create_by!(email: error_params["email"]) | ||
@error = current_site.issues.create_with(description: 'dasdasdsa').find_or_create_by(page_title: error_params["page_title"]) | ||
error_params | ||
subscriber = current_site.subscribers.create_with(name: "test").find_or_create_by!(email: error_params["email"]) | ||
@error = current_site.issues.create_with(description: 'dasdasdsa').find_or_create_by(page_title: error_params["page_title"]) | ||
@error.increment!(:occurrences) | ||
|
||
SubscriberIssue.create_with(issue_id: @error.id).find_or_create_by(subscriber_id: subscriber.id) | ||
message = Message.create(content: error_params["message"], issue_id: @error.id) | ||
SubscriberIssue.create_with(issue_id: @error.id).find_or_create_by(subscriber_id: subscriber.id) | ||
message = Message.create(content: error_params["message"], issue_id: @error.id) | ||
end | ||
|
||
|
||
private | ||
private | ||
def error_params | ||
if params[:error].is_a?(String) | ||
error_params ||= JSON.parse(params[:error]) | ||
else | ||
error_params ||= params[:error] | ||
end | ||
params.require(:error).permit(:status, :description, :page_title, :message, :name, :email) | ||
end | ||
params[:error] = JSON.parse(params[:error]) if params[:error].is_a?(String) | ||
params.require(:error).permit(:status, :description, :page_title, :message, :name, :email) | ||
end | ||
end |