Topic: trying to figure out the Rails way on some code...
Here's the situation: I'm using attachment_fu in an "upload" model. this model has validation for file sizes, content type, etc. and "validates_as_attachment"
In my /view/ method, an ID is passed in, and the user has a file field to upload a file. this form submits to /add_file/, which looks like this:
@file = Upload.new(params[:tab])
flash[:notice] = "File Uploaded!"
@file.errors.each do |i|
flash[:error] = "Error uploading file: This file type is not accepted."
flash[:error] = "Error uploading file: file size is too large. Please keep it under 2 megabytes."
redirect_to :action=>:view, :id => params[:tab][:tab_id]
this is working fine, however, there must be a better, more efficient way. What I tried to do in the view.rhtml for /view/ is to put: error_messages_for :tab, and ditch the whole @file.errors loop in favor of a redirect, but that didn't work because the redirect cleared out the errors.
so my next attempt was to replace the redirect with a render_action, however this got bloated quick as I needed to set params[:id] = params[:tab][:tab_id] to emulate /view/some_id, then call the method itself so it would run some of the queries I have that reply on an ID in the URL, then do the render_action. All said and done, my error_messages_for still didn't output a thing.
so that brought me to make this post to try and progress with my understanding of rails. inch by inch...