### ERB 可以生成 js 片段,当然 SLIM 也可以 ##### app/controllers/x_controller.rb ``` def a respond_to :js # 如果 a 同名文件只有 js 片段 可以省略 end ``` #### app/views/x/a.js.slim ``` // 单行 js 代码: | var $table = $('table#table'); | var $tbody = $table.find('tbody'); | $tbody.empty().end().siblings('.pagination').remove().end().siblings('.total_page').remove(); // 多行 js 代码: - if response&.code == Response::Code::SUCCESS | BootstrapDialog.alert({ type: BootstrapDialog.TYPE_SUCCESS, title: '', message: '删除#{obj}成功', buttonLabel: '确定' }); - else | BootstrapDialog.alert({ type: BootstrapDialog.TYPE_DANGER, title: '删除#{obj}失败', message: '#{response.message}', buttonLabel: '确定' }); ```