Skip to content

Instantly share code, notes, and snippets.

@aaronmcadam
Created May 1, 2014 15:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaronmcadam/11454190 to your computer and use it in GitHub Desktop.
Save aaronmcadam/11454190 to your computer and use it in GitHub Desktop.
class QuestionTagsController < ApplicationController
def index
@manager = QuestionTagsManager.new(params)
respond_to do |format|
format.html { set_breadcrumbs }
format.json { render json: @manager.tags }
end
end
def new
@manager = QuestionTagsManager.new(params)
set_breadcrumbs
end
def create
@manager = QuestionTagsManager.new(params)
if @manager.save_tag
redirect_to(question_tags_path(@manager.question),
notice: I18n.t("tagging.created"))
else
set_breadcrumbs
render(action: "new")
end
end
def edit
@manager = QuestionTagsManager.new(params)
set_breadcrumbs
end
def update
@manager = QuestionTagsManager.new(params)
if @manager.update_tag(params[:tag])
redirect_to(question_tags_path(@manager.question),
notice: I18n.t("tagging.updated"))
else
set_breadcrumbs
render(:edit)
end
end
def destroy
@manager = QuestionTagsManager.new(params)
@manager.destroy_tag(params.slice(:orphan))
redirect_to(question_tags_path(@manager.question),
notice: I18n.t("tagging.destroyed"))
end
private
def set_breadcrumbs
home_breadcrumb
project_breadcrumb
task_breadcrumb
question_breadcrumb
end
def project_breadcrumb
add_breadcrumb(label: @manager.project_title,
link: project_path(@manager.project_id),
icon: "icon_project")
end
def task_breadcrumb
add_breadcrumb(label: @manager.task_title, link: task_url,
icon: "icon_task")
end
def task_url
params = [@manager.project_id, @manager.task_id]
{
"survey" => project_responses_path(*params),
"discussion" => project_posts_path(*params)
}.fetch(@manager.task_type)
end
def question_breadcrumb
add_breadcrumb(label: @manager.question_summary,
link: question_tags_path(@manager.question_id),
icon: "icon_tag")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment