So is this the correct way:
def create
bad =[]
begin
@tour_type = TourType.new(params[:tour_type])
if @tour_type.save
render :update do |page|
page << "Redbox.close;"
page.call "ProtoGrowl.success", "Succesfully created
#{@tour_type.name}"
end
end
rescue ActiveRecord::MultiparameterAssignmentErrors
if params[:tour_type][:usual_price_number].blank?
bad << "Usual price must not be 0.00"
end
rescue ActiveRecord::RecordInvalid
bad << "#{@tour_type.errors.full_messages}"
end
unless bad.empty?
flash.now[:error] = "#{bad.length} Errors have occured in this form"
flash.now[:items] = bad
render :update do |page|
page[:flash].replace_html :partial => 'shared/flash_box' and return
end
end
end
On Friday, February 25, 2011 9:37:05 PM UTC-6, bacrossland wrote:
>
> That is because you did not setup your error handling correctly. A rescue
> block is done within a begin and end. You don't have that. You have rescues
> just tossed into your code. The format should look something like this:
>
> begin
> puts 10/0 #Bad code which will throw a ZeroDivisionError
> rescue ZeroDivisionError
> puts "Stop dividing by zero or the universe will end!"
> end
>
> See the docs on error handling for more information.
>
> http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_exceptions.html
>
> Thanks,
> B.
>
> On Fri, Feb 25, 2011 at 9:17 PM, Me <[email protected]> wrote:
>
>> I have this code below, it still gives me the error,
>> ActiveRecord::MultiparameterAssignmentErrors. It is not catching the rescue
>> for some reason. Ideas?
>>
>> def create
>> bad =[]
>> @tour_type = TourType.new(params[:tour_type])
>> if @tour_type.save
>> render :update do |page|
>> page << "Redbox.close;"
>> page.call "ProtoGrowl.success", "Succesfully created #{@
>> tour_type.name}"
>> end
>> end
>> rescue ActiveRecord::MultiparameterAssignmentErrors
>> if params[:tour_type][:usual_price_number].blank?
>> bad << "Usual price must not be 0.00"
>> end
>>
>> rescue ActiveRecord::RecordInvalid
>> bad << "#...@tour_type.errors.full_messages}"
>>
>> unless bad.empty?
>> flash.now[:error] = "#{bad.length} Errors have occured in this form"
>> flash.now[:items] = bad
>> render :update do |page|
>> page[:flash].replace_html :partial => 'shared/flash_box' and
>> return
>> end
>> end
>> end
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Ruby on Rails: Talk" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/rubyonrails-talk?hl=en.
>>
>
>
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.