UPDATE
I answered my question below, but I am still asking for a prettier way to achieve my goal. I have a feeling my controller knows too much about how to do things.
I have a create action in my VideoController :
def create
method = 'get_' + params[:video][:provider] + '_video_id'
provider_video_id = Video.send(method, params[:video][:url])
thumb = Video.get_thumb_from_youtube(provider_video_id)
@video = Video.new(params[:video], :provider_video_id => provider_video_id, :thumb => thumb, :views => 0, :likes => 0)
if @video.save!
redirect_to video_path('1'), notice:'Video added successfully.'
else
render :new
end
end
I call Video.new with params[:video] with get its information from a form the user fills in. I then manipulate the URL the user passed in with the form to recover the video_provider_idand thethumb.
However, Rails is not saving the video with provider_video_idand thumb... I get this error on save :
Validation failed: Thumb can't be blank, Thumb is invalid, Provider video can't be blank
My guess is the newmethod doesn't accept extra parameters...