Question

I would like to make some text within a table editable to get a similar result as best_in_place. However I'm not sure if this is the best gem/solution to suit my needs. If I'm not mistake this would require a form for each table row.. which could get very ugly.

Is there a solution/gem that allows me to edit text (page name) without a from and updates the resource (page) using Ajax?

My view:

 <% @pages.each do |page| %>
      <tr>
        <td><%= page.name %></td>
        <td><%= link_to "Navigation", toggle_menu_page_path(page),remote: true, id: "menu_button_#{page.id}", class: menu_button(page) %></td>
         <td><%= link_to "Publish", toggle_publish_page_path(page),remote: true, id: "publish_button_#{page.id}", class: publish_button(page) %></td>
        <td><%= link_to 'Destroy',page,method: :delete, data: { confirm: 'Are you sure?' }, class: "btn btn-default" %></td>
        <td><%= link_to 'Edit', edit_page_path(page), class: "btn btn-default" %></td>
      </tr>
      <% end %>
Was it helpful?

Solution

https://github.com/bernat/best_in_place

Ddemo here http://bipapp.heroku.com/users/49

Then to update a page name you would need:

<%= best_in_place @page, :name, :type => :input %>

p.s. The demo looks not so fancy, but there are a many options that this gem provide to customize css classes.

OTHER TIPS

You could try jEditable It is a jQuery Plugin.

Here is a Demo

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top