【发布时间】:2018-06-29 11:11:36
【问题描述】:
我正在使用本地参数渲染 smart_listing 部分视图:
smart_listing_render(:user_ldaproles, locals: {ldapuser: @ldapuser})
本地参数ldapuser 适用于渲染的第一个页面。
但是当我点击 smart_listing 的下一页时,本地参数 ldapuser 是 nil。
13:05:52 web.1 | Started GET "/ldapusers/kru0096?user_ldaproles_smart_listing%5Bpage%5D=2" for 10.0.1
13:27:09 web.1 | Rendered ldapusers/show.js.erb (1946.1ms)
13:27:09 web.1 | Completed 500 Internal Server Error in 1980ms (ActiveRecord: 4.2ms)
13:27:09 web.1 |
13:27:09 web.1 |
13:27:09 web.1 |
13:27:09 web.1 | NameError - undefined local variable or method `ldapuser' for #<#<Class:0x00007f4f6c
bb2638>:0x00007f4f6d4a5ab0>
13:27:09 web.1 | Did you mean? @ldapuser:
13:27:09 web.1 | app/views/ldapusers/_ldaproles.haml:24:in `block in _app_views_ldapusers__ldaprole
s_haml__4226213442704361194_69988992008260'
13:27:09 web.1 | app/views/ldapusers/_ldaproles.haml:10:in `_app_views_ldapusers__ldaproles_haml__4
226213442704361194_69988992008260'
13:27:09 web.1 | app/views/ldapusers/show.js.erb:2:in `_app_views_ldapusers_show_js_erb__8937577382
81268117_69989556369100'
我可以使用全局参数@ldapuser,但 gem rails_best_practicies 不喜欢它。
在转到下一页时,如何获取传递给smart_listing_render 的本地参数以保持其值?
编辑:
app/views/ldapusers/show.js.erb:
<%= smart_listing_update :user_ldaproles %>
【问题讨论】:
-
文件 app/views/ldapusers/show.js.erb 包含什么?
-
@JagdeepSingh 文件添加到问题
-
@JagdeepSingh 我注意到我的
smart_listing_update是错误的。我把它改成了正确的名字,错误发生了一点变化。 -
@JagdeepSingh 天哪,我现在明白了。
show.js.erb必须包含局部参数,例如<%= smart_listing_update :user_ldaproles, locals: {ldapuser: @ldapuser} %>
标签: ruby-on-rails ruby smart-listing