Nameserve: Undefined method `send_data' for Clonedatabase:Class

Asked

Viewed 279 times

0

Rails does not find method send_data

clone_database.rb    

require 'zip'

class CloneDatabase < ApplicationController
  def self.make_clone
    zip_data = 'a'.to_json
    send_data zip_data, type: 'application/zip', filename: 'Topic.zip'
  end
end

test rake.

  namespace :my_namespace do
      desc 'Clone database'
        task clone_database: :environment do
          CloneDatabase.make_clone
        end
    end

1 answer

0

Hi @Ruan,

I don’t think you’re finding it because send_data is an instance method not? and you are wanting to use it within a class method.

Try to remove the self of his method make_clone and in his task try something like:

clone_database = CloneDatabase.new
clone_database.response = ActionDispatch::Response.new
clone_database.make_clone
  • quiet, doing now

  • the error has changed, that’s good

  • NoMethodError: undefined method content_type=' for nil:Nilclass`

  • @Ruannawe is complicated, as you are not doing a request ( which is the natural behavior for an action) some variables will not be set, which will take a lot of work to do this manually. What’s your goal with this? We can find an alternative solution better than calling an action like this.

  • @Ruannawe edited my reply with a possible solution, manually uploaded the controller’s answer to try to avoid the error with content_type.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.