0

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.

  • I think without javascript it is not possible – Divyarajsinh Jul 29 '22 at 07:56
  • You can make use of Jquery best_in_place https://github.com/bernat/best_in_place. This will make the field editable on click and will save it after changes – Vishal Jain Jul 29 '22 at 11:48
  • 1
    Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Jul 31 '22 at 01:04
  • Welcome to SO, questions that fit along the lines of "how would I do this?" without any specific code hardly ever get an answer, and when they do, the answer is likely to misunderstand your intent. Please check out https://stackoverflow.com/help/asking – Chiperific Aug 15 '22 at 01:06

1 Answers1

1

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

Chiperific
  • 4,428
  • 3
  • 21
  • 41