I have a controller with several actions that take: year and: month as attributes from a URL. I made a private check_date method to check the date and check the date in the future.
def check_date(year, month) if month < 1 || month > 12 || year < 2000 flash[:notice] = I18n.t 'archive.invalid_date' redirect_to :action => 'index' elsif year > Date.today.year || (year == Date.today.year && month > Date.today.month) flash[:notice] = I18n.t 'archive.no_future' redirect_to :action => 'month_index', :year => Date.today.year, :month => Date.today.month, :type => params[:type] end end
Is there a rail to complete controller execution after redirect_to?
The ways I can think of is to either throw an exception after redirect_to, or return a value from check_date and check it in every action that calls it - something like
def month_index year = params[:year].to_i month = params[:month].to_i if !check_date(year, month) return ... end
But I wonder if there are any good rails. I was half hoping that by calling the redirect_to rails, I find out that I want to stop, but this does not seem to be happening.
ruby-on-rails error-handling
Hamish Downer May 04 '09 at 16:21 2009-05-04 16:21
source share