简体   繁体   中英

How to implement editable field for an object in Ruby?

I need to find a way my tasks could be edited in such a manner without updating a page. Maybe somebody know how to do it? I know it applies to Angularjs. But I really haven't found any information for my purpose.

When you click on some task, you can edit its content. 在此处输入图片说明

Can anybody help?

I would use the gem 'best_in_place' you can follow implementing it from the In-Place Editing rails cast

what you have to do is in app/assets/javascripts/application.js add the following files

//= require jquery.purr
//= require best_in_place

app/assets/javascripts/model_name.js.coffee

jQuery ->
  $('.best_in_place').best_in_place()

lastly on model/show.html.erb

<p>
  <b>Field Name:</b>
  <%= best_in_place @model, :field_name %>
</p>
<p>
  <b>Email:</b>
  <%= best_in_place @model, :email %>
</p>

That should be all you kneed. Happy coding

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM