Skip to content

Commit

Permalink
Fixed the add_error to work with js call
Browse files Browse the repository at this point in the history
  • Loading branch information
aurelianb committed Sep 2, 2015
1 parent 0f7c17f commit 38744f3
Showing 1 changed file with 33 additions and 37 deletions.
70 changes: 33 additions & 37 deletions app/controllers/api/v1/errors_controller.rb
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

0 comments on commit 38744f3

Please sign in to comment.