Sha256: 52fde4ccae2b2fcbfddcfdd277a1eefea56b8ae2c33a0a3e96649e81857cf58d

Contents?: true

Size: 1.79 KB

Versions: 19

Compression:

Stored size: 1.79 KB

Contents

module Rostra
  module Base
    class QuestionsController < Rostra::ApplicationController
      load_and_authorize_resource

      def vote
        rostra_user.vote_on(@question, params[:vote_direction])

        respond_to do |format|
          format.html { redirect_to @question }
          format.js
        end
      end

      def toggle_following
        if rostra_user.following?(@question)
          rostra_user.followed_questions.delete(@question)
        else
          rostra_user.question_followings.create(question: @question, send_email_notifications: false)
        end

        respond_to do |format|
          format.html { redirect_to @question }
          format.js
        end
      end

      def tags
        tags = Question.tag_counts.where("name like ?", "%#{params[:q]}%").limit(10)
        respond_to do |format|
          format.js { render :js => tags.map { |tag| {value: tag.name} }.to_json }
        end
      end


      def index
        if params[:tag_search].present?
          @questions = Question.tagged_with(params[:tag_search]).order('created_at desc').page(params[:page])
        else
          @questions = Question.order('created_at desc').page(params[:page])
        end
      end

      def show
        @answers = @question.answers.order('votes_count desc')
        impressionist(@question) # increments page views
      end

      def new
      end

      def edit
      end

      def create
        if @question.save
          redirect_to questions_path, notice: 'Your question has been posted.'
        else
          render :new
        end
      end

      def update
        if @question.update_attributes(params[:question])
          redirect_to @question, notice: 'Question was successfully updated.'
        else
          render :edit
        end
      end

    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
rostra-0.3.6 app/controllers/rostra/base/questions_controller.rb
rostra-0.3.5 app/controllers/rostra/base/questions_controller.rb
rostra-0.3.4 app/controllers/rostra/base/questions_controller.rb
rostra-0.3.3 app/controllers/rostra/base/questions_controller.rb
rostra-0.3.2 app/controllers/rostra/base/questions_controller.rb
rostra-0.3.1 app/controllers/rostra/base/questions_controller.rb
rostra-0.2.1 app/controllers/rostra/base/questions_controller.rb
rostra-0.2.0 app/controllers/rostra/base/questions_controller.rb
rostra-0.1.26 app/controllers/rostra/base/questions_controller.rb
rostra-0.1.25 app/controllers/rostra/base/questions_controller.rb
rostra-0.1.24 app/controllers/rostra/base/questions_controller.rb
rostra-0.1.23 app/controllers/rostra/base/questions_controller.rb
rostra-0.1.22 app/controllers/rostra/base/questions_controller.rb
rostra-0.1.21 app/controllers/rostra/base/questions_controller.rb
rostra-0.1.20 app/controllers/rostra/base/questions_controller.rb
rostra-0.1.19 app/controllers/rostra/base/questions_controller.rb
rostra-0.1.18 app/controllers/rostra/base/questions_controller.rb
rostra-0.1.17 app/controllers/rostra/base/questions_controller.rb
rostra-0.1.16 app/controllers/rostra/base/questions_controller.rb