Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7831737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T11:52:02+00:00 2026-06-02T11:52:02+00:00

I’m having issue with a youtube video being destroyed properly in a nested belongs_to

  • 0

I’m having issue with a youtube video being destroyed properly in a nested belongs_to has_one relationship between a sermon and its sermon video when using :dependent => :destroy.

I’m using the youtube_it gem and have a fairly vanilla setup.

The relevant bits below:

the video controller —

def destroy
  @sermon = Sermon.find(params[:sermon_id])
  @sermon_video = @sermon.sermon_video

  if SermonVideo.delete_video(@sermon_video)
    flash[:notice] = "video successfully deleted"
  else
    flash[:error] = "video unsuccessfully deleted"
  end
  redirect_to dashboard_path
end

the video model —

belongs_to :sermon

def self.yt_session
  @yt_session ||= YouTubeIt::Client.new(:username => YouTubeITConfig.username , :password => YouTubeITConfig.password , :dev_key => YouTubeITConfig.dev_key)
end

def self.delete_video(video)
  yt_session.video_delete(video.yt_video_id)
  video.destroy
    rescue
      video.destroy
end

the sermon model —

has_one :sermon_video, :dependent => :destroy

accepts_nested_attributes_for :sermon_video, :allow_destroy => true

In the above setup, all local data is removed successfully; however, the video on youtube is not.

I have tried to override the destroy action with a method in the model, but probably due a failing of my understanding, can only get either the video deleted from youtube, or the record deleted locally, never both at the same time (I posted the two variants below and their results).

This only serves to destroy the local record —

def self.destroy
  @yt_session ||= YouTubeIt::Client.new(:username => YouTubeITConfig.username , :password => YouTubeITConfig.password , :dev_key => YouTubeITConfig.dev_key)
  @yt_session.video_delete(self.yt_video_id)

  @sermon_video.destory
end

This only serves to destroy the video on youtube, but not the local resource —

def self.destroy
  @yt_session ||= YouTubeIt::Client.new(:username => YouTubeITConfig.username , :password => YouTubeITConfig.password , :dev_key => YouTubeITConfig.dev_key)
  @yt_session.video_delete(self.yt_video_id)
end

Lastly, the link I’m using to destroy the sermon, in case it helps —

<%= link_to "Delete", [@sermon.church, @sermon], :method => :delete %>

Thanks for your help, very much appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T11:52:03+00:00Added an answer on June 2, 2026 at 11:52 am

    It looks as though I have just solved the issue; however, I’ll leave it open for a bit in case someone has a more elegant / appropriate solution.

    In the sermon video model I added —

    before_destroy :kill_everything
    
    def kill_everything
      @yt_session ||= YouTubeIt::Client.new(:username => YouTubeITConfig.username , :password => YouTubeITConfig.password , :dev_key => YouTubeITConfig.dev_key)
      @yt_session.video_delete(self.yt_video_id)
    end
    

    And the key thing, I believe, to have added in the sermon model was this —

    accepts_nested_attributes_for :sermon_video, :allow_destroy => true
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.