Search code examples
ruby-on-railserror-handlingbest-in-place

ruby on rails best_in_place gem field name change on error display


So i have setup the best_in_place gem [https://github.com/bernat/best_in_place] but i am facing a little problem when my column i try to edit looks like title_name and when an error occurs it shows it like

'title_name can't be blank,is too short (minimum is 1 characters)'

I would like to edit the way the gem handles the error display so it will replace the _ with space and maybe make it a little user-friendly

EDIT:

checking the response i get via Firebug is:

{"title_name":["can't be blank","is too short (minimum is 1 characters)"]}

where in the gem demo http://bipapp.heroku.com/users/59

["Last name has invalid length","Last name can't be blank"]

which is a bit different...

EDIT2:

post.rb

class Post < ActiveRecord::Base
  attr_accessible :post_id, :title_name, :total_items, :user_id

  validates :title_name, :presence => true, :length => { :in => 1..50 }

  belongs_to :user, :foreign_key => 'post_id'

  self.primary_key = :post_id

  def to_param
    "#{post_id}"
  end
end

Solution

  • SOLUTION:

    i found that best_in_place gem uses the following method to display the errors when the save was not completed

    respond_with_bip(@user
    

    which was attached to the format.json as

    format.json { respond_with_bip(@user) }
    

    so replacing the way i show the errors via json with this code solved the problem.