title: has_many dependent: destroy throwing 'wrong number of arguments (0 for 1)'
body: <p>So I have Users, Media and Comments in my application.
  Both the user and media have a 
  <code>has_many :comments</code>.
  Comments model has a <code>belongs_to</code> for both users and media.</p>
  
  <p>Now I also have the <code>dependent: destroy</code> option after has_many on both user and media.</p>
  
  <p>Now when I enter the index page for users, everything is fine but when I enter the index page for media, it will throw error on the <code>has_many</code> method: <code>wrong number of arguments (0 for 1)</code></p>
  
  <p>All models have their corresponding controllers with corresponding methods defined like <code>destroy</code> method and so on.</p>
  
  <p>What could be the problem here?</p>
  
  <p>Media model: </p>
  
  <pre><code>class Media &lt; ActiveRecord::Base
      belongs_to :user
      before_create :randomize_file_name
  
      private
          def randomize_file_name
              extension = File.extname(image_video_file_name).downcase
              self.image_video.instance_write(:file_name, "#{SecureRandom.hex(8)}#{extension}")
          end
  
      has_many :comments, dependent: destroy
  end
  </code></pre>
  
  <p>User model:</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
      validates :name, presence: true, length: {maximum: 50}
  
      enum role: [:user, :moderator, :admin]
      after_initialize :set_default_role, :if =&gt; :new_record?
  
      def set_default_role
          self.role ||= :user
      end
  
      # Include default devise modules. Others available are:
      # :confirmable, :lockable, :timeoutable and :omniauthable
      devise :database_authenticatable, :registerable,
             :recoverable, :rememberable, :trackable, :validatable
  
      has_many :medias, dependent: :destroy
      has_many :comments, dependent: :destroy
  end
  </code></pre>
  
  <p>Comments model:</p>
  
  <pre><code>class Comment &lt; ActiveRecord::Base
      belongs_to :user
      belongs_to :media
  
      validates :text, presence: true, length: { maximum: 255 }
      validates :user_id, presence: true
      validates :media_id, presence: true
  end
  </code></pre>
  
  <p>Full error:</p>
  
  <pre><code>ArgumentError - wrong number of arguments (0 for 1):
    activerecord (4.1.6) lib/active_record/querying.rb:8:in `destroy'
    app/models/media.rb:19:in `&lt;class:Media&gt;'
    app/models/media.rb:1:in `&lt;top (required)&gt;'
    activesupport (4.1.6) lib/active_support/dependencies.rb:443:in `block in load_file'
    activesupport (4.1.6) lib/active_support/dependencies.rb:633:in `new_constants_in'
    activesupport (4.1.6) lib/active_support/dependencies.rb:442:in `load_file'
    activesupport (4.1.6) lib/active_support/dependencies.rb:342:in `require_or_load'
    activesupport (4.1.6) lib/active_support/dependencies.rb:480:in `load_missing_constant'
    activesupport (4.1.6) lib/active_support/dependencies.rb:180:in `const_missing'
    activesupport (4.1.6) lib/active_support/dependencies.rb:512:in `load_missing_constant'
    activesupport (4.1.6) lib/active_support/dependencies.rb:180:in `const_missing'
    app/controllers/media_controller.rb:5:in `index'
    actionpack (4.1.6) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
    actionpack (4.1.6) lib/abstract_controller/base.rb:189:in `process_action'
    actionpack (4.1.6) lib/action_controller/metal/rendering.rb:10:in `process_action'
    actionpack (4.1.6) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
    activesupport (4.1.6) lib/active_support/callbacks.rb:113:in `call'
    activesupport (4.1.6) lib/active_support/callbacks.rb:149:in `block in halting_and_conditional'
    activesupport (4.1.6) lib/active_support/callbacks.rb:229:in `block in halting'
    activesupport (4.1.6) lib/active_support/callbacks.rb:166:in `block in halting'
    activesupport (4.1.6) lib/active_support/callbacks.rb:166:in `block in halting'
    activesupport (4.1.6) lib/active_support/callbacks.rb:229:in `block in halting'
    activesupport (4.1.6) lib/active_support/callbacks.rb:166:in `block in halting'
    activesupport (4.1.6) lib/active_support/callbacks.rb:86:in `run_callbacks'
    actionpack (4.1.6) lib/abstract_controller/callbacks.rb:19:in `process_action'
    actionpack (4.1.6) lib/action_controller/metal/rescue.rb:29:in `process_action'
    actionpack (4.1.6) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
    activesupport (4.1.6) lib/active_support/notifications.rb:159:in `block in instrument'
    activesupport (4.1.6) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
    activesupport (4.1.6) lib/active_support/notifications.rb:159:in `instrument'
    actionpack (4.1.6) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
    actionpack (4.1.6) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
    activerecord (4.1.6) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
    actionpack (4.1.6) lib/abstract_controller/base.rb:136:in `process'
    actionview (4.1.6) lib/action_view/rendering.rb:30:in `process'
    actionpack (4.1.6) lib/action_controller/metal.rb:196:in `dispatch'
    actionpack (4.1.6) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
    actionpack (4.1.6) lib/action_controller/metal.rb:232:in `block in action'
    actionpack (4.1.6) lib/action_dispatch/routing/route_set.rb:82:in `dispatch'
    actionpack (4.1.6) lib/action_dispatch/routing/route_set.rb:50:in `call'
    actionpack (4.1.6) lib/action_dispatch/journey/router.rb:73:in `block in call'
    actionpack (4.1.6) lib/action_dispatch/journey/router.rb:59:in `call'
    actionpack (4.1.6) lib/action_dispatch/routing/route_set.rb:678:in `call'
    warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
    warden (1.2.3) lib/warden/manager.rb:34:in `call'
    rack (1.5.2) lib/rack/etag.rb:23:in `call'
    rack (1.5.2) lib/rack/conditionalget.rb:25:in `call'
    rack (1.5.2) lib/rack/head.rb:11:in `call'
    actionpack (4.1.6) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
    actionpack (4.1.6) lib/action_dispatch/middleware/flash.rb:254:in `call'
    rack (1.5.2) lib/rack/session/abstract/id.rb:225:in `context'
    rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call'
    actionpack (4.1.6) lib/action_dispatch/middleware/cookies.rb:560:in `call'
    activerecord (4.1.6) lib/active_record/query_cache.rb:36:in `call'
    activerecord (4.1.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:621:in `call'
    activerecord (4.1.6) lib/active_record/migration.rb:380:in `call'
    actionpack (4.1.6) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
    activesupport (4.1.6) lib/active_support/callbacks.rb:82:in `run_callbacks'
    actionpack (4.1.6) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
    actionpack (4.1.6) lib/action_dispatch/middleware/reloader.rb:73:in `call'
    actionpack (4.1.6) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
    better_errors (2.0.0) lib/better_errors/middleware.rb:84:in `protected_app_call'
    better_errors (2.0.0) lib/better_errors/middleware.rb:79:in `better_errors_call'
    better_errors (2.0.0) lib/better_errors/middleware.rb:57:in `call'
    actionpack (4.1.6) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
    actionpack (4.1.6) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
    railties (4.1.6) lib/rails/rack/logger.rb:38:in `call_app'
    railties (4.1.6) lib/rails/rack/logger.rb:20:in `block in call'
    activesupport (4.1.6) lib/active_support/tagged_logging.rb:68:in `block in tagged'
    activesupport (4.1.6) lib/active_support/tagged_logging.rb:26:in `tagged'
    activesupport (4.1.6) lib/active_support/tagged_logging.rb:68:in `tagged'
    railties (4.1.6) lib/rails/rack/logger.rb:20:in `call'
    quiet_assets (1.0.3) lib/quiet_assets.rb:23:in `call_with_quiet_assets'
    actionpack (4.1.6) lib/action_dispatch/middleware/request_id.rb:21:in `call'
    rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
    rack (1.5.2) lib/rack/runtime.rb:17:in `call'
    activesupport (4.1.6) lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
    rack (1.5.2) lib/rack/lock.rb:17:in `call'
    actionpack (4.1.6) lib/action_dispatch/middleware/static.rb:64:in `call'
    rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
    railties (4.1.6) lib/rails/engine.rb:514:in `call'
    railties (4.1.6) lib/rails/application.rb:144:in `call'
    passenger (4.0.53) lib/phusion_passenger/rack/thread_handler_extension.rb:74:in `process_request'
    passenger (4.0.53) lib/phusion_passenger/request_handler/thread_handler.rb:141:in `accept_and_process_next_request'
    passenger (4.0.53) lib/phusion_passenger/request_handler/thread_handler.rb:109:in `main_loop'
    passenger (4.0.53) lib/phusion_passenger/request_handler.rb:455:in `block (3 levels) in start_threads'
  </code></pre>