acts_as_attachment custom filename - parent name


I am trying to follow. in the actor_name variable - do you want the actor’s name? if so, isn’t Actor.find(self.actor_id).name enough? what does the sanitize_filename do?

Does your user choose the actor for which they are uploading the file from a dropdown or type on the actor name, or how does your app know what actor your user is trying to upload a file for?

Just to make sure that I understand correctly - your Actor model has an action_movie_id?

assuming that the model instance of the file_upload has actor_id, does not have to be saved yet, then maybe these changes will help? (its possible that I am completely missing the point - had very little sleep last night :] )

def full_filename actor = Actor.find(self.actor_id) file_system_path = (thumbnail ? thumbnail_class :self).attachment_options[:file_system_path]

actor_name = action_movie_name = ActionMovie.find(actor.action_movie_id).name File.join(RAILS_ROOT, file_system_path, action_movie_name, ‘actors’,actor_name, ‘mug_shot’, thumbnail_name_for(thumbnail))


also, with the changing the filename from my_picture_of_actor_in_las_vegas.jpg to actor_name.jpg to actor_name.jpg - what is your strategy to do this?

regards ivor

doesn’t look like I can help much, except that the saving issue.

You can create models, give them attributes and use them without ever saving them to the database. It is possible however, that the values are never assigned in the first place, are you using text_field or text_field_tag (or ekwivalent for other html components) in your view? text_field applies the value entered directly to the model while text_field_tag merely gives you the value in the controller.

text_field :actor, :name will automatically assign the name value, while text_field_tag :name will only provide you with params[:name] in your controller. in your controller you will then have to do actor = new Actor(:name => params[:name]) manually.

Also, if you are using text_field then you have to pass a actor model from the controller to the view.

I am not the best person to give you advice - have been programming actionscript for a while and the bit of rails I know is rusty but I seem to remember that - perhaps someone else can give you better advice and post it here so I can learn aswell.