如何从Ruby on Rails中的控制器调用coffee脚本函数

时间:2018-09-17 07:19:08

标签: ruby-on-rails coffeescript

在下面的示例中,您可以从咖啡脚本中指导我如何调用咖啡功能(例如更新表)

updateTable = (data) ->
  $('#employee-table tbody').append """
    <tr>
      <td>#{data.name}</td>
      <td>#{data.position}</td>
      <td>#{data.office}</td>
      <td>#{data.extension}</td>
      <td>#{data.start_date}</td>
      <td><a href="/employees/#{data.id}">Show</a></td>
      <td><a href="/employees/#{data.id}/edit">Edit</a></td>
      <td><a data-confirm="Are you sure?" rel="nofollow" data-method="delete" href="/employees/#{data.id}">Delete</a></td>
    </tr>
  """
  return

$ ->
  $('#add_employee').on 'ajax:success', (data) ->
    $('#add_employee')[0].reset()
    return
  pusher = new Pusher('<%= ENV["PUSHER_KEY"] %>',
    cluster: '<%= ENV["PUSHER_CLUSTER"] %>'
    encrypted: true)
  channel = pusher.subscribe('employee')
  channel.bind 'new', (data) ->
    updateTable data
    return
  return

0 个答案:

没有答案