ajax datatables介绍了如何在ajax响应中添加按钮
我的问题是,我不知道如何添加不同的按钮,这些按钮保持在使用gem进行服务器端处理的状态。例如,在尝试进行服务器端处理之前,我的观点是这样的ajax datatables介绍了如何在ajax响应中添加按钮,ajax,ruby-on-rails-4,datatables,Ajax,Ruby On Rails 4,Datatables,我的问题是,我不知道如何添加不同的按钮,这些按钮保持在使用gem进行服务器端处理的状态。例如,在尝试进行服务器端处理之前,我的观点是这样的 <% if current_user.sales_manager? || current_user.admin? %> <td> <%= link_to t('.destroy', :default => t("helpers.links.destroy")), bill_
<% if current_user.sales_manager? || current_user.admin? %>
<td>
<%= link_to t('.destroy', :default => t("helpers.links.destroy")),
bill_sale_path(bill_sale),
:method => :delete %>
</td>
<% end %>
那么,我如何使用服务器端处理来提供属于if条件的不同按钮呢?虽然我没有使用gem,但我使用了带有Rails的datatables,这就是我所做的: 将按钮作为变量存储在数组之前,然后只调用数组中的变量
records.map do |record|
record_button = ''
record_button = button_to('A', button1_path) if condition1
record_button = button_to('B', button2_path) if condition2
record_button = button_to('C', button3_path) if condition3
record_button = button_to('D', button4_path) if condition4
[
link_to('Show', bill_sale_path(record), class: 'btn-xs btn-link'),
record.customer.name,
record.seller.name,
l(record.date_sold, format: :short),
record.payment_type.name,
record.payed,
number_to_currency(record.total),
record_button
]
end
如果适合您的需要,您也可以使用案例陈述
一定要加上
def_delegator :@view, :button_to
到文件的顶部,根据:
def_delegator :@view, :button_to