diff --git a/app/controllers/survey/choices_controller.rb b/app/controllers/survey/choices_controller.rb index 4a0ed30..82264cc 100644 --- a/app/controllers/survey/choices_controller.rb +++ b/app/controllers/survey/choices_controller.rb @@ -83,12 +83,19 @@ class Survey::ChoicesController < ApplicationController # DELETE /survey/choices/1 # DELETE /survey/choices/1.json def destroy - @survey_choice = Survey::Choice.find(params[:id]) + @survey_choice = Survey::Choice.find(params[:id]) + + if @survey_choice.answers.count>0 + redirect_to action: :show +else + @divid = divid_for(@survey_choice) @survey_choice.destroy respond_to do |format| format.html { redirect_to survey_choices_url } format.json { head :no_content } - end + format.js +end +end end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 5575d6a..8a93542 100755 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -43,14 +43,14 @@ m.save language_path(locale: target_locale) end def ffi1_icon (name) - content_tag("i","", class: "ffi1-"+name ) + content_tag("i","", class: "ficon ffi1-"+name ) end def ffi2_icon (name) - content_tag("i","", class: "ffi2-"+name ) + content_tag("i","", class: "ficon ffi2-"+name ) end def ff_icon (name) - content_tag("i","", class: name ) + content_tag("i","", class: "ficon "+name ) end def ffi1_list diff --git a/app/views/survey/choices/_choice.html.erb b/app/views/survey/choices/_choice.html.erb index 709757c..7f75eb8 100644 --- a/app/views/survey/choices/_choice.html.erb +++ b/app/views/survey/choices/_choice.html.erb @@ -7,7 +7,7 @@ if current_user.nil? else value=(current_user.id.nil?)? false : choice.answers.where(user_id: current_user.id).count>0 cstyle=(value) ? "true" :"false" - t= link_to(raw("" + choice.html+ (( choice.picture.nil? || choice.picture.to_s.empty?) ? "":image_tag(choice.picture.thumb.url))), answer_survey_question_path(choice.question, params: {survey_question: {selected: [choice.id]}}),class: "choice-"+cstyle,remote: true ) + t= link_to(raw("" + choice.html+ (( choice.picture.nil? || choice.picture.to_s.empty?) ? "":image_tag(choice.picture.thumb.url))), answer_survey_question_path(choice.question, params: {survey_question: {selected: [choice.id]}}),class: "choice choice-"+cstyle,remote: true ) end %> @@ -15,5 +15,5 @@ end <%= t %> <%= link_to fa_icon("pencil"), edit_survey_choice_path(choice) , class: "btn btn-link navbar-btn" , remote: true %> -<%= link_to fa_icon("pencil"), delete_survey_choice_path(choice) , class: "btn btn-link navbar-btn" , remote: true %> +<%= link_to fa_icon("trash"), survey_choice_path(choice) , class: "btn btn-link navbar-btn" , remote: true , method: :delete, data: { confirm: 'Are you sure?' } %> <% end %>