Ruby On Rails-Make content on show page content-editable

379 Views Asked by At

I would like to make my show page content editable by double clicking on the content and after I update that content, then that updated content would also be save in the database. I am working on Ruby on Rails. Any suggestions, how can make my content editable.

1

There are 1 best solutions below

0
On

Rails 7 has Hotwire

This can also be accomplished with AJAX and UJS

Basically, when a user clicks on an area you want to be content-editable, you would replace that static section of the DOM with a form and a field. Then either clicking a submit button or clicking away would trigger a remote PATCH or PUT call to update the database and you'd again replace that section of the DOM with a static section containing the newly edited data.

There are quite a few good tutorials out there on this subject.

And even some gems for you to use: https://www.ruby-toolbox.com/categories/rails_in_place_editing