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
Post a Comment