Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Question < ActiveRecord::Base
- attr_accessible :crowd_id, :question_type, :body, :priority, :choices_attributes
- belongs_to :crowd
- has_many :choices
- accepts_nested_attributes_for(
- :choices,
- :reject_if => lambda{ |c| c[:body].blank? }
- )
- validates_presence_of :crowd_id, :body, :question_type
- TYPES = {
- 'True/False' => 'boolean',
- 'Poll' => 'poll',
- 'Score' => 'score',
- 'Video' => 'video'
- }
- ## Class Methods ##
- # Convenience method for creating a new question
- # Returns: a saved Question object
- # NOTE: this method should be used throughout the app
- # whenever a new question needs to be created
- def self.set(params={})
- q = (id = params[:id]) ? Question.find(id) : Question.new
- params.each do |k, v|
- q.send("#{k}=", v)
- end
- q.save!
- return q
- end
- ## Instance methods ##
- # Add a question the given user's question queue
- # Requires: a User object
- # Returns: boolean
- def add_user(user, params={})
- params = {
- :question => self,
- :user => user
- }
- QuestionQueue.set(params)
- end
Add Comment
Please, Sign In to add comment