Get extra information from ActiveRecord::RecordNotFound in Rails -



Get extra information from ActiveRecord::RecordNotFound in Rails -

i handle recordnotfound error in application_controller.rb follow:

rescue_from activerecord::recordnotfound, :with => :record_not_found private def record_not_found flash[:error] = "oops, cannot find record" redirect_to :back end

but more information, such class/table name of record not found. how should go it?

thank you.

say example,

begin @user = user.find(params[:id]) rescue activerecord::recordnotfound flash[:notice] = "#no such record in user id :: {params[:id]} on #{action_name}" end

update

flash[:notice] = t('flash.recordnotfound',:class_name => self.class.name, :column_name => params[:id], :action_name => action_name)

now in config/locales/en.yml (this help translate, refer i18n here)

flash: recordnotfound: "sorry, no record od %{column_name} in class %{class_name} found on action %{action_name}"

if not want utilize locales set info in flash[:notice] itself.

more dynamic ?

write function , utilize same flash [:notice] there. wont wound @ all.

want more info ?

heres quick solution, <%= params%> in views know whats going , whats coming. can open rails console , play along different actions , on.

user = user.new user.save user.errors.messages

all of plenty data, think.

good luck.

ruby-on-rails activerecord

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -