我的show.js.erb代码
<% if @status = "answered"%>
$('#all_answered').html('<%= escape_javascript render(partial: "trackers/all_answered") %>');
$('#paginator').html('<%= escape_javascript(paginate(@answered, :remote => true,:param_name => "all_answered").to_s) %>');
<% else %>
$('#all_questions').html('<%= escape_javascript render(partial: "trackers/all_questions") %>');
$('#paginator').html('<%= escape_javascript(paginate(@all_questions, :remote => true,:param_name => "all_questions").to_s) %>');
<% end %>
视图
<div id="paginator">
<%= paginate @answered, :remote => true, :param_name => "all_answered" %>
</div>
<div id="all_answered">
<%= render partial: "all_answered" %>
</div>
控制器
@answered = Tracker.where("user_id = ? AND answered = ?", current_user, true).page(params[:all_answered]).per(1)
if(params[:all_answered])
@status = "answered"
end
在我看来,我对同一页面的另一部分也有类似的分页。问题是,当我点击一个,另一个也被触发,他们混淆了。我怎么能把他们分开?
答案 0 :(得分:0)
当你说他们“被触发......并且混淆了”你是什么意思?
要在一个页面中包含多个paginations,请唯一地命名param_name:就像您从show.js.erb中所做的那样。即。 :all_answered和:all_questions。
在你的show.js.erb中你的条件是否应该改变?
<% if @status = "answered"%> to <% if @status == "answered"%>
最后,如果这不会影响其他代码,请考虑直接测试params参数,而不是在控制器中设置实例变量。 即
<% unless params[:all_answered].blank? %>