mirror of
https://github.com/Retrospring/retrospring.git
synced 2025-03-31 04:52:12 +02:00
question#content now has a validation.
This commit is contained in:
parent
293837984e
commit
72c259bd0d
2 changed files with 12 additions and 3 deletions
|
@ -4,9 +4,16 @@ class Ajax::QuestionController < ApplicationController
|
||||||
params.require :anonymousQuestion
|
params.require :anonymousQuestion
|
||||||
params.require :rcpt
|
params.require :rcpt
|
||||||
|
|
||||||
question = Question.create!(content: params[:question],
|
begin
|
||||||
author_is_anonymous: params[:anonymousQuestion],
|
question = Question.create!(content: params[:question],
|
||||||
user: current_user)
|
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?
|
unless current_user.nil?
|
||||||
current_user.increment! :asked_count unless params[:anonymousQuestion] == 'true'
|
current_user.increment! :asked_count unless params[:anonymousQuestion] == 'true'
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
class Question < ActiveRecord::Base
|
class Question < ActiveRecord::Base
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
has_many :answers
|
has_many :answers
|
||||||
|
|
||||||
|
validates :content, length: { maximum: 200 }
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue