techvision/brails4

View on GitHub
app/controllers/questions_controller.rb

Summary

Maintainability
A
25 mins
Test Coverage
class QuestionsController < ApplicationController
  before_filter :find_questionable

  def show
    @question = Question.offset(rand(@questionable.questions.count)).first 
  end

  private

  def find_questionable
    klass = [Level,Topic,Content].detect { |c| params["#{c.name.underscore}_id"]}
    @questionable = klass.find(params["#{klass.name.underscore}_id"])
  end
end