每次单击链接时,我都想刷新 Rails 中的部分内容,但它似乎没有做任何事情。
有人可以发现错误吗?
index.html.erb
<% @users.each do |u| %>
<% if !u.nil? and u.department_id == department.id %>
<%= link_to "#{u.first_name} #{u.last_name}", professor_refresh_path(u.id), remote: true %>
<% end %>
<% end %>
<div id="profile"></div>
_profile.html.erb
Hello, <%= user %>
刷新.js.erb
$('#profile').html('<%=j render partial: "/professors/profile", locals: {user: @user} %> ');
教授控制器.rb
def refresh
@user = @user + 1
respond_to do |format|
format.html
format.js
end
end
路线.rb
resources :professors do
get 'refresh'
end