Class: Admin::FormResponsesController
- Inherits:
-
Noodall::Admin::BaseController
- Object
- Noodall::Admin::BaseController
- Admin::FormResponsesController
- Includes:
- SortableTable::App::Controllers::ApplicationController
- Defined in:
- app/controllers/noodall/admin/form_responses_controller.rb
Instance Method Summary collapse
Instance Method Details
#destroy ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/controllers/noodall/admin/form_responses_controller.rb', line 56 def destroy @form.responses = @form.responses.reject{|r| r.id.to_s == params[:id]} @form.save flash[:notice] = "Response was successfully deleted." respond_to do |format| format.html { redirect_to(noodall_admin_form_form_responses_url(@form)) } format.xml { head :ok } end end |
#index ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/controllers/noodall/admin/form_responses_controller.rb', line 16 def index if @form.nil? @responses = Noodall::FormResponse.paginate(:per_page => 1000, :page => params[:page]) else @responses = @form.responses.paginate(:per_page => 1000, :page => params[:page]) end respond_to do |format| format.html # index.html.erb format.xml { render :xml => @responses } format.csv do csv_string = Abstracted_CSV_Class.generate do |csv| header_row = @form.fields.map do |field| field.name end header_row += ['Date', 'IP', 'Form Location'] csv << header_row for response in @responses response_row = @form.fields.map do |field| begin value = response.send(field.underscored_name) value.respond_to?(:join) ? value.join(', ') : value rescue NoMethodError => e nil end end response_row += [response.created_at.to_formatted_s(:long), response.ip, response.referrer] csv << response_row end end send_data csv_string, :filename => "#{@form.title} responses - #{Time.now.to_formatted_s(:db)}-#{@responses.current_page}.csv", :type => 'text/csv', :disposition => 'attachment' end end end |
#mark_as_not_spam ⇒ Object
74 75 76 77 78 79 80 81 82 |
# File 'app/controllers/noodall/admin/form_responses_controller.rb', line 74 def mark_as_not_spam @response = @form.responses.find(params[:id]) @response.approve! FormMailer.form_response(@form, @response).deliver unless @form.email.blank? FormMailer.form_response_thankyou(@form, @response).deliver redirect_to(noodall_admin_form_form_responses_url(@form)) end |
#mark_as_spam ⇒ Object
68 69 70 71 72 |
# File 'app/controllers/noodall/admin/form_responses_controller.rb', line 68 def mark_as_spam @response = @form.responses.find(params[:id]) @response.mark_as_spam! redirect_to(noodall_admin_form_form_responses_url(@form)) end |