diff --git a/app/controllers/survey/questions_controller.rb b/app/controllers/survey/questions_controller.rb index ee33a3f..9b9d282 100644 --- a/app/controllers/survey/questions_controller.rb +++ b/app/controllers/survey/questions_controller.rb @@ -2,7 +2,7 @@ class Survey::QuestionsController < ApplicationController # GET /survey/questions # GET /survey/questions.json load_and_authorize_resource - + acts_as_flagable def index @survey_questions = Survey::Question.all respond_to do |format| diff --git a/app/models/survey/question.rb b/app/models/survey/question.rb index 1064273..7fa1c12 100644 --- a/app/models/survey/question.rb +++ b/app/models/survey/question.rb @@ -6,6 +6,7 @@ class Survey::Question < ActiveRecord::Base include IsCommentable FLAG_ICONS={"delete" => "fa fa-trash"} scope :templates, ->{ where(flag_template:true)} + acts_as_flagable def add_yesno_choices c=Survey::Choice.new(title: "Ja") diff --git a/app/views/neuigkeiten/show.html.erb b/app/views/neuigkeiten/show.html.erb index 4c04915..6ade453 100755 --- a/app/views/neuigkeiten/show.html.erb +++ b/app/views/neuigkeiten/show.html.erb @@ -35,9 +35,9 @@

<%= render partial: "neuigkeit_view", object: @neuigkeit %> - <% @neuigkeit.questions.each do |q| %> - <%= render q%> - <% end %> +<% @neuigkeit.questions.each do |q| %> + <%= render q if can? :show, q %> +<% end %> diff --git a/lib/flagable.rb b/lib/flagable.rb index f1b50f0..e3215c8 100644 --- a/lib/flagable.rb +++ b/lib/flagable.rb @@ -16,9 +16,9 @@ module Flagable module LocalInstanceMethods def flag - fi = controller_name.classify.constantize::FLAG_ICONS + fi = controller_path.classify.constantize::FLAG_ICONS - @obj=controller_name.classify.constantize.find(params[:id]) + @obj=controller_path.classify.constantize.find(params[:id]) lflag=("flag_"+params[:flag]).to_sym authorize! lflag, @obj unless params[:flag].nil? || params[:flag].empty? || params[:value].nil? @@ -53,7 +53,7 @@ module Flagable v end def flaglinkid(flag) - return self.class.to_s + "_" + self.id.to_s + "_flag_"+flag.to_s + return self.class.to_s.gsub("::","_") + "_" + self.id.to_s + "_flag_"+flag.to_s end end end @@ -62,9 +62,10 @@ module Flagable def flag_link(obj, flag, text="") flag=flag.to_s fi = obj.class::FLAG_ICONS + fc = obj.class::FLAG_CONFIRM value=obj.send("flag_"+flag) cstyle=(value) ? "true" :"false" - link_to ff_icon(fi[flag]), url_for({controller: obj.class.name.tableize,action: :flag, flag: flag, value: !value, theme: nil, locale: nil, id: obj.id}), remote: true, class:("flag-"+cstyle +" flag-"+flag + "-"+cstyle ), id: obj.flaglinkid(flag) + link_to ff_icon(fi[flag]), url_for({controller: obj.class.name.tableize,action: :flag, flag: flag, value: !value, theme: nil, locale: nil, id: obj.id}), remote: true, class:("flag-"+cstyle +" flag-"+flag + "-"+cstyle ), id: obj.flaglinkid(flag), data: { confirm: (((!fc.nil? && fc["flag_"+flag].nil?) ? fc["flag_"+flag].nil? : nil)) } end end end