开发者

Can't display validation errors with best_in_place gem

I am using the best_in_place gem with Rails 3.0.9. Seems lik开发者_高级运维e 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?


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.


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; }
}


Take care. Add best_in_place.purr plugin instead of jquery.purr in application.js. It worked for me.

//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require best_in_place.purr
//= require best_in_place
//= require_tree .
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜