I have a rails site where I allow a user to upload an mp3 file to
create a podcast. Once uploaded (using paperclip) I use mp3info to
read the metadata and then populate the model information if it has
been specified. I decided to redo this in hobo.

I think I am having trouble with the order of callbacks or something.
The model code I have is pasted below. It is currently strewn with
various "attempts" of me trying to debug, etc. with puts, so please
don't laugh too much. I also copied/pasted it so it's entirely
possible I have a typo, but I don't think so. My problem is that the
after_audio_post_process callback gets called, but for some reason it
doesn't appear to be "saving" the information to the db. Is this
called after the model is saved? If so, do I need to call something in
assign_episode_info to save my model after I have updated the title,
description, etc.? I tried to put a self.save in at the bottom and
that didn't work (I got an error on that), so I'm assuming I have to
do something else.

I got it to save once last night, but have no idea what I changed to
get it that way since my vision was blurring from exhaustion. Am I
calling something in the wrong order, etc? Also, if there is somewhere
that I can look to find out what order these things are called in I'm
willing to read a bit on my own.

Thanks for any help. I'm on RC2 if it's important.

Joey


class Episode < ActiveRecord::Base

  hobo_model # Don't put anything above this

  require 'rubygems'
  require 'mp3info'

  fields do
    title       :string, :name => true
    artist      :string
    description :text
    tagstring   :string
    timestamps
  end

  has_many :episode_categories, :through
=> :episode_cat_joins, :accessible => true
  has_many :episode_cat_joins, :dependent => :destroy

  has_many :tags, :through => :tag_joins, :accessible => true
  has_many :tag_joins, :dependent => :destroy

  children :episode_categories

  has_attached_file :audio,
    :url => "/system/
audio/:class/:attachment/:id_:normalized_audio_file_name",
    :path => ":rails_root/public/system/
audio/:class/:attachment/:id_:normalized_audio_file_name"

  validates_attachment_presence :audio,
    :message => "must be specified before continuing."
  validates_attachment_content_type :audio, :content_type =>
[ 'application/mp3', 'application/x-mp3', 'audio/mpeg', 'audio/
mp3','audio/x-m4a','audio/x-mp3' ],
    :message => "is the only valid file type for an episode
attachment."
  validates_attachment_size :audio, :less_than => 15.megabytes,
    :message => "file must be less than 15 Megabytes."

  Paperclip.interpolates :normalized_audio_file_name do |attachment,
style|
    attachment.instance.normalized_audio_file_name
  end
  def normalized_audio_file_name
    "#{self.id}-#{self.audio_file_name.gsub( /[^a-zA-Z0-9_\.]/,
'_')}"
  end

  after_audio_post_process :assign_episode_info
  def assign_episode_info
    #self.size = self.mp3_file_size
    Mp3Info.open(audio.to_file.path) do |audio_info|
      self.title =  if (audio_info.tag.title.nil? ||
audio_info.tag.title.blank?)
                      "Untitled Episode"
                    else
                      audio_info.tag.title
                    end
      puts "************" + self.title
      self.artist = if (!audio_info.tag.artist.nil? && !
audio_info.tag.artist.blank?)
                      audio_info.tag.artist
                    end
      puts "************" + self.artist
      self.description =  if (!audio_info.tag.comments.nil? && !
audio_info.tag.comments.blank?)
                            audio_info.tag.comments.gsub!("?","")
                            puts "*********** Nothing was nil or blank
for description"
                          else
                            "Sermons from the Willette church of
Christ"
                            puts "************something was blank"
                          end
      #puts "************" + self.description
    end
  end
  # --- Permissions --- #

  def create_permitted?
    acting_user.administrator?
  end

  def update_permitted?
    acting_user.administrator?
  end

  def destroy_permitted?
    acting_user.administrator?
  end

  def view_permitted?(field)
    true
  end

end

-- 
You received this message because you are subscribed to the Google Groups "Hobo 
Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/hobousers?hl=en.

Reply via email to