导轨|在Datatables Rails上添加操作按钮(删除,编辑等)

时间:2012-10-05 09:29:34

标签: jquery ruby-on-rails datatable

如何使用json / ajax方法添加删除和编辑按钮列?

<%= link_to image_tag('icons/edit.png'), editcontent_path(page), :title => "edit" %>
<%= link_to image_tag('icons/delete.png'), page, method: :delete, data: { confirm: 'Are you sure?' }, :title => "delete"  %> 

我想输入datatables / page_datatables.rb

class PagesDatatable
  delegate :params, :truncate, :html_safe, :link_to, to: :@view

  .....

  def data
    pages.map do |page|
      [
          page.name
          page.permalink,
          truncate(page.content, :length => 160).html_safe
          #####  I want to input here ####

      ]
    end
  end

  ......
  ......

end

请帮助..

2 个答案:

答案 0 :(得分:1)

这对我有用,

class PagesDatatable
delegate :params, :truncate, :html_safe, :link_to, :edit_page_path, :page, to: :@view

    .....

    .....

    def data
        pages.map do |page|
          [
              page.name,
              page.permalink,
              truncate(page.content, :length => 160).html_safe,
              link_to("edit", edit_page_path(page)),
              link_to("delete", page, method: :delete, data: { confirm: 'Are you sure?' }) 

          ]
        end
      end


end

答案 1 :(得分:0)

需要查看您的路线。但是,您可以通过以下示例获得灯光:

<%= link_to image_tag('icons/edit.png'), [:edit, page], :title => "edit" %>
<%= link_to image_tag('icons/delete.png'), page, :method => :delete, :confirm => 'Are you sure?', :title => "delete"  %>