Class: Rostra::Base::QuestionsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/rostra/base/questions_controller.rb

Direct Known Subclasses

QuestionsController

Instance Method Summary collapse

Methods inherited from ApplicationController

#can_participate_in_rostra?, #main_app_login_path, #main_app_signup_path, #rostra_user

Methods included from Config

setup

Instance Method Details

#createObject



55
56
57
58
59
60
61
# File 'app/controllers/rostra/base/questions_controller.rb', line 55

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

#editObject



52
53
# File 'app/controllers/rostra/base/questions_controller.rb', line 52

def edit
end

#indexObject



36
37
38
39
40
41
42
# File 'app/controllers/rostra/base/questions_controller.rb', line 36

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

#newObject



49
50
# File 'app/controllers/rostra/base/questions_controller.rb', line 49

def new
end

#showObject



44
45
46
47
# File 'app/controllers/rostra/base/questions_controller.rb', line 44

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

#tagsObject



28
29
30
31
32
33
# File 'app/controllers/rostra/base/questions_controller.rb', line 28

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

#toggle_followingObject



15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/rostra/base/questions_controller.rb', line 15

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

#updateObject



63
64
65
66
67
68
69
# File 'app/controllers/rostra/base/questions_controller.rb', line 63

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

#voteObject



6
7
8
9
10
11
12
13
# File 'app/controllers/rostra/base/questions_controller.rb', line 6

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

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