question#content now has a validation.
This commit is contained in:
parent
293837984e
commit
72c259bd0d
|
@ -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'
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
class Question < ActiveRecord::Base
|
||||
belongs_to :user
|
||||
has_many :answers
|
||||
|
||||
validates :content, length: { maximum: 200 }
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue