【问题标题】:How do I update a record using ajax with editable text? (Rails 4)如何使用带有可编辑文本的 ajax 更新记录? (导轨 4)
【发布时间】:2014-02-13 11:33:13
【问题描述】:

我想让表格中的一些文本可编辑以获得与best_in_place 类似的结果。但是,我不确定这是否是满足我需求的最佳宝石/解决方案。如果我没记错的话,这将需要为每个表格行提供一个表格。这可能会变得非常难看。

是否有解决方案/gem 允许我在没有 from 的情况下编辑文本(页面名称)并使用 Ajax 更新资源(页面)?

我的看法:

 <% @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 %>

【问题讨论】:

    标签: jquery ruby-on-rails ajax ruby-on-rails-4 gem


    【解决方案1】:

    https://github.com/bernat/best_in_place

    Ddemo 在这里http://bipapp.heroku.com/users/49

    然后更新您需要的页面名称:

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

    附言该演示看起来并不那么花哨,但是这个 gem 提供了许多选项来自定义 css 类。

    【讨论】:

      【解决方案2】:

      你可以试试jEditable 它是一个 jQuery 插件。

      Here is a Demo

      【讨论】:

      • 有最新的 gem 吗?我发现的那些似乎不活跃。
      • 似乎不是这样,但我对上一个版本没有任何问题。很容易实现,以后不会出问题
      猜你喜欢
      • 1970-01-01
      • 2016-09-12
      • 2012-07-31
      • 2014-05-23
      • 1970-01-01
      • 2019-03-09
      • 2023-04-11
      • 1970-01-01
      • 2017-01-27
      相关资源
      最近更新 更多