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

  • SEARCH
  • Home
  • 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 8046767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:53:54+00:00 2026-06-05T05:53:54+00:00

Thanks for any help in advance. I would like to set id3 tag data

  • 0

Thanks for any help in advance.

I would like to set id3 tag data in my database as attributes for my model MasterSong. Specifically, title, artist, and album.

create_table :master_songs do |t|
  t.integer :user_id
  t.has_attached_file :m_song
 **- t.string :title
 - t.string :artist
 - t.string :album**

In my model I’m using a callback to set the data before the object(master_song) is saved.

before_save :set_id3_tags_in_database

def set_id3_tags_in_database
TagLib::MPEG::File.open(self.m_song.path) do |file|
   tag = file.id3v2_tag
   tag.title
   tag.album
   tag.artist
end
  self.update_attributes(:title => tag.title,
  :artist => tag.artist,
  :album => tag.album)
end

I’m pretty sure my syntax is the problem. The object seems to hit an error

undefined method `title' for nil:NilClass with an infinite loop

Controller create action is normal:

 def create
   @master_song = current_user.master_songs.build(params[:master_song])

   respond_to do |format|
    if @master_song.save
     format.html { redirect_to @master_song, notice: 'Master song was successfullycreated.' }
   end

What am I doing wrong here?
Update:
def set_id3_tags
z = TagLib::MPEG::File.open(self.m_song.path) do |file|
tag = file.id3v2_tag
tag.title
end
self.update_attribute!(:title => z)
end

get stack level too deep error now.

  • 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-05T05:53:56+00:00Added an answer on June 5, 2026 at 5:53 am

    OK! So I did it, after playing and playing and playing.

    def set_id3_tags
    z = TagLib::MPEG::File.open(self.m_song.path) do |file|
     unless tag.nil?
      tag = file.id3v2_tag
      self.title = tag.title
      self.album = tag.album
      self.artist = tag.artist
    
      else
    end
    

    end

    Adding the if title.nil? did it for me. Callbacks are weird but definitely valuable. Hope this helps someone else.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Thanks for any help in advance, I can't wrap my SQL skills around this
I am using c# .net. Thanks in advance for any help. I have searched
Still learning WPF....thanks for any help. Is there any way to Refactor this: <ListBox
Do any libraries exist with this functionality? Any recommendations would be useful. Thanks.
I have a spreadsheet where I would like to model the progress of several
I am new to mySQL and would like some help with a query I'm
I would like to check if a digit appears a set amount of times
I have a page on my DotNetNuke site and I would like to set
As title Welcome any comment Thanks interdev
Is there any way to suppress Compiler warnings ?? Thanks

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.