diff --git a/app/controllers/ajax/question_controller.rb b/app/controllers/ajax/question_controller.rb index 98df8d72..e7387107 100644 --- a/app/controllers/ajax/question_controller.rb +++ b/app/controllers/ajax/question_controller.rb @@ -4,9 +4,16 @@ class Ajax::QuestionController < ApplicationController params.require :anonymousQuestion params.require :rcpt - question = Question.create!(content: params[:question], - author_is_anonymous: params[:anonymousQuestion], - user: current_user) + begin + question = Question.create!(content: params[:question], + author_is_anonymous: params[:anonymousQuestion], + user: current_user) + rescue ActiveRecord::RecordInvalid + @status = :rec_inv + @message = "Your question is too long." + @success = false + return + end unless current_user.nil? current_user.increment! :asked_count unless params[:anonymousQuestion] == 'true' diff --git a/app/models/question.rb b/app/models/question.rb index 76bdb939..5c86d72f 100644 --- a/app/models/question.rb +++ b/app/models/question.rb @@ -1,4 +1,6 @@ class Question < ActiveRecord::Base belongs_to :user has_many :answers + + validates :content, length: { maximum: 200 } end