This is a frontend editor for rails using the frontendeditor gem and ckeditor.
-
Add
gem 'frontendeditor_ckeditor'
in your Gemfile -
Add file named frontendeditor.coffee (for example) and put this :
//= require jquery //= require jquery_ujs //= require underscore //= require backbone //= require jquery.ui.effect-highlight.js //= require ckeditor/init_ckeditor //= require frontend_editor/frontend_editor $(document).ready -> FrontendEditor.init()
-
Include the new file where you to have an editable content
-
Add a css like this (feel free to customize it) :
footer { position:fixed; left:0px; bottom:0px; width:100%; background:#FFF; padding-left: 10px; } footer a { margin: 10px; } footer a:hover { cursor: pointer }
-
Place your the part than you whant to be editable in the helper like this :
<%= editable(@post) { @post.body } %>
-
Now, when you on the editable link, the field is hillighted. Click on the save button to save it.
You can have an editable zone, with more options, like this :
<%= editable(@post, id: 2, object: 'pages', method: :title) do %>
<% @post.title %>
<% end %>
- The
id
attribute is the id of the model you whant to change. By default it'smodel.id
- The object is the name of your route for the action. By default it's the plural name of the class.
- The method is the attribute than you want to change. By default it's 'body'.
To customize the toolbar, you can add a tag with the id frontend_toolbar
. The link with class editable-mode
is the button to show other options. The button with the class save
is the button to save. Finally, the button with cancel
class is to cancel the editor.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request