question#content now has a validation.

This commit is contained in:
nilsding 2014-12-08 15:34:37 +01:00
parent 293837984e
commit 72c259bd0d
2 changed files with 12 additions and 3 deletions

View File

@ -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'

View File

@ -1,4 +1,6 @@
class Question < ActiveRecord::Base
belongs_to :user
has_many :answers
validates :content, length: { maximum: 200 }
end