【发布时间】:2013-06-17 15:56:17
【问题描述】:
我想在每次点击链接时刷新 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 %>
refresh.js.erb
$('#profile').html('<%=j render partial: "/professors/profile", locals: {user: @user} %> ');
professors_controller.rb
def refresh
@user = @user + 1
respond_to do |format|
format.html
format.js
end
end
routes.rb
resources :professors do
get 'refresh'
end
【问题讨论】:
-
是没有重新加载还是只是reloading the old value of the partial?
-
@OldPro 它根本没有重新加载。 : (
-
那它做了什么?
-
@NickGinanto 好吧,它现在什么也没做。我想要它做的是将 1 添加到用户变量,然后用新值刷新部分。但是,它根本没有加载,并且在我希望部分去的 index.html.erb 文件中没有显示任何内容。
-
看我的回答,也许对你有一点帮助(等一下,我要先写出来)
标签: ruby-on-rails ruby