Sology / smart_listing

Ruby on Rails data listing gem with built-in sorting, filtering and in-place editing.
http://showcase.sology.eu/smart_listing
MIT License
478 stars 138 forks source link

Pass locals params doesn't work #148

Closed Kani999 closed 6 years ago

Kani999 commented 6 years ago

I'm rendering smart_listing_render with local parameter user.

.page-header
  %h2 Rolify - Roles
= smart_listing_controls_for(:rolify_roles, class: 'form-inline text-right') do
  .form-group.filter.input-append
    = text_field_tag :filter, '', class: 'search form-control',
                     placeholder: 'Search...', autocomplete: :off
  %button.btn.btn-primary.disabled{ type: 'submit' }
    %span.glyphicon.glyphicon-search
= smart_listing_render(:rolify_roles, locals: { user: @user })

The page is loaded fine, but when I hit Next button, the local variable is unknown.

12:01:17 web.1     | 
12:01:17 web.1     | 
12:01:17 web.1     | 
12:01:17 web.1     | NameError - undefined local variable or method `user' for #<#<Class:0x00007f09b7577520>:0x00007f09b7083de8>
12:01:17 web.1     | Did you mean?  @user:
12:01:17 web.1     |   app/views/users/_rolify_roles.html.haml:25:in `block in _app_views_users__rolify_roles_html_haml___3348197901261425424_69839850803520'
12:01:17 web.1     |   app/views/users/_rolify_roles.html.haml:12:in `_app_views_users__rolify_roles_html_haml___3348197901261425424_69839850803520'
12:01:17 web.1     |   app/views/users/show.js.erb:2:in `_app_views_users_show_js_erb__3214774511846350922_69839851120280'
12:01:17 web.1     | 

user.id is unknown when navigating to another page.

- smart_listing.collection.each do |role|
          %tr
            %td
              = role.id
            %td
              = role.name
            %td
              - unless role.resource_type.blank?
                = resource_type_path(role)
            %td
              - unless role.resource_id.blank?
                = resource_id_path(role)
            %td
              = link_to '', user_role_path(user.id, role.id),
Kani999 commented 6 years ago

Solved!

https://stackoverflow.com/questions/51100434/smart-listing-locals-params-does-not-work/51100872#51100872

I did not expect that js.erb file has to contain the local parameter too

<%= smart_listing_update :rolify_roles, locals: { user: @user} %>