On Jun 30, 11:34 am, Max W. [email protected] wrote:
Can you explain in some more detail what you’re trying to do here?
Basically taking a file that the user browsed on their local computer
(in this case my own computer since I’m testing it), manipulate the
file directory name and run it through an outside program. The outside
program creates a file that the user can view and I don’t want the
ruby code activating again when the user reopens the show page.
Ok, well then there’s a bug in your code: don’t give up, try and fix it.
Post your code up please.
This is the code for my first solution:
In Controller
def show
@order = Order.find(params[:id])
respond_to do |format|
if @order then
format.html {redirect_to ‘/display’, :notice => “This task has
already been created”}
format.xml {render :xml => @order}
else
order = @order.logfile
@log_file_cut = order.gsub(/[\w ! # $ % ^ & * + -]+\.log$/,
‘*.log’)
system(‘C:\analog_6.0\analog.exe’, @log_file_cut)
time = @order.created_at.strftime("%m%d%y_%H%M")
watchforfile = "C:\\rails_project\\test2_copy\\public\\output\
\errors.txt"
File.rename watchforfile, watchforfile+“.#{time}.html”
StatusReport.deliver_confirm(@order) #sends email when analog
has completed
format.html {redirect_to(:action => 'edit')} # show.html.erb
format.xml { render :xml => @order }
end
end
rescue ActiveRecord::RecordNotFound
logger.error(“Attempt to access invalid task #{params[:id]}”)
flash[:notice] = “Invalid task”
redirect_to “/display”
end
If you think about it, it’ll run the first set of code when I create a
new object, not the actual ruby code to runs the outside program
The other solution I tried was to create an after_filter on the create
method. The issue with this was that I couldn’t get the parameters
from the form and manipulate it.
The code in an after filter can access params. Post your code up
please.
My Second Solution In Controller
after_filter :analog, :only => [:create]
protected
def analog
order = params[:logfile]
@log_file_cut = order.gsub(/[\w ! # $ % ^ & * + -]+.log$/,
‘*.log’)
system(‘C:\analog_6.0\analog.exe’, @log_file_cut)
end
end
Thanks for the help 