Skip to content

Commit

Permalink
fixed invalid msg for json
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego Salazar committed Jan 25, 2017
1 parent 3841035 commit 3ab420e
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions app/controllers/recommendations_controller.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
class RecommendationsController < ApplicationController
def index
if params[:subtopic].to_s.strip.blank?
flash[:alert] = "Please provide a subtopic parameter: '/recommendations?subtopic=X' or paste the subtopic into the search field above."
redirect_to root_path and return
@error = "Please provide a subtopic parameter: '/recommendations?subtopic=X' or paste the subtopic into the search field above."
end
unless SubTopic.where(subtopic_id: params[:subtopic]).exists?
flash[:alert] = "Invalid subtopic"
redirect_to root_path and return
@error = "Invalid subtopic"
end

if @error.present?

respond_to do |format|
format.html do
flash[:alert] = @error
redirect_to root_path and return
end
format.json do
render json: @error, status: :not_found and return
end
end
end

per = params.fetch :per, 4
Expand Down

0 comments on commit 3ab420e

Please sign in to comment.