在Rails中使用select_tag而不是link_to来实现ajax

时间:2017-08-23 12:49:21

标签: jquery ruby-on-rails ruby ajax

在我的信息中心index.html.erb视图中,我有几个关于ajax调用的链接:

<% @employees.each do |employee| %>       
  <%= link_to employee.full_name, employee_details_path(:assigned_user_id => employee.assigned_user_id), remote: true, class: "employee-select" %></br>        
<% end %>

点击该链接会显示部分内容。

dashboard_controller.rb

def employee_details
  @latest_report = Report.where(:assigned_user_id => params[:assigned_user_id])
end

employee_details.js.erb

$('#employee-details').html("<%= escape_javascript (render partial: 'employee_details') %>");

我现在想要的是在点击时调用ajax而不是多个链接,我想要一个调用ajax的select_tag。类似的东西:

<%= select_tag "employees", options_from_collection_for_select(@employees, "assigned_user_id", "full_name"),
                                      :prompt => "Please select an employee",
                                      :onchange => "call ajax and render partial" %>

我现在完全被困住了。

0 个答案:

没有答案