Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't display validation errors with best_in_place gem

I am using the best_in_place gem with Rails 3.0.9. Seems like I have everything working. I followed the install instructions and I am able to click on an item, edit it and save all in the one spot with ajax.

However, when testing the validation functionality but putting in bogus data, the error message does not display.

I am not sure if this is supposed to be done magically through javascript, or if I am supposed to supply some sort of div tag or something where the error message can be displayed.

Checking into this in firebug, I am getting the correct json response. In my case I can see

["Debts has invalid length"]

but this does not get rendered anywhere.

Is there anything else I need to put in the view to render the validation error? It is supposed to be displayed via purr.js. Do I need to do anything besides put the javascript files in my public directory, initiate best_in_place in application.js and put

<p>
  <b>Debts:</b>
  <%= best_in_place @prospect, :debts, :type => :input %>
</p>

In the view?

like image 462
Oscar Avatar asked Aug 21 '11 09:08

Oscar


2 Answers

Your problem sounds just like mine: checking carefully at Railscast #302, I noticed that the error message was printing but in the bottom left of the page, hard to see and easy to miss.

The purr CSS code listed that page will format and display it more clearly on the web page.

Hope this helps.

like image 146
Daniel May Avatar answered Oct 11 '22 09:10

Daniel May


Your should add the right controller action

def update
  ..
  respond_to do |format|   
    format.json { render json: @prospect } 
  end
end  

or use the respond_with_bip helper instead. And do not forget to define the .purr CSS class, the "Best In Place" gem uses the jQuery Purr plugin to display error messages:

.purr {
  position: fixed;
  top: 30px;
  right: 100px;
  width: 250px;
  padding: 20px;
  background-color: #FCC;
  border: solid 2px #C66;
  &:first-letter { text-transform: uppercase; }
}
like image 36
0x4a6f4672 Avatar answered Oct 11 '22 08:10

0x4a6f4672