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

Undefined local variable or method `smart_listing_resource' #151

Closed Kani999 closed 6 years ago

Kani999 commented 6 years ago

I want to use in-place editing for nested resource request_comments in project_requests show.

resources :project_requests do
    resources :request_comments, except: :index
end

When I set up everything and calls CREATE action, I get an error

Undefined local variable or method `smart_listing_resource'

My files are:

_app/controllers/project_requestscontroller.rb

def show
...
    request_comments = @project_request.request_comments
    @request_comments = smart_listing_create(:request_comments, request_comments, partial: "request_comments/list")

_app/views/projectrequests/show.html.haml

...
-#= smart_listing_render(:request_comments, locals: { project_request: @project_request })
= render template: 'request_comments/index', request_comments: @request_comments

_app/views/requestcomments/index.html.haml

...
= smart_listing_render(:request_comments, locals: {project_request: @project_request})

_app/views/request_comments/list.html.haml

...
      - smart_listing.collection.each do |request_comment|
        %tr.editable{data: {id: request_comment.id}}
          = smart_listing.render request_comment: request_comment, project_request: project_request, partial: "request_comments/request_comment", locals: {request_comment: request_comment, project_request: project_request}

      = smart_listing.item_new colspan: 9, link: new_project_request_request_comment_path(project_request), locals: { project_request: project_request }

_app/views/requestcomments/new.js.erb

<%= smart_listing_item :request_comments, :new, @request_comment, "request_comments/form", locals: { project_request: @project_request }, project_request: @project_request %>

_app/views/requestcomments/create.js.erb

<%= smart_listing_item :request_comments, :create, @request_comment,
                       @request_comment.valid? ? "request_comments/request_comment" : "request_comments/form" %>

_app/views/request_comments/form.html.haml

%td{colspan: 9}
  = simple_form_for([@project_request, @request_comment] ,
    url: @request_comment.new_record? ? project_request_request_comments_path(@project_request) : project_request_request_comment_path([@project_request, @request_comment]),
    remote: true, html: { class: "form-horizontal" }) do |f|
...

Error Log

13:51:07 web.1     | Started POST "/project_requests/17/request_comments" for 10.0.131.29 at 2018-09-06 13:51:07 +0200
13:51:07 web.1     | Processing by RequestCommentsController#create as JS
13:51:07 web.1     |   Parameters: {"utf8"=>"✓", "request_comment"=>{"science_comment"=>"test", "science_score"=>"5", "computational_comment"=>"test", "computational_score"=>"5", "socioeconomic_comment"=>"test", "socioeconomic_score"=>"5", "audit_comment"=>"test"}, "commit"=>"Create Request comment", "project_request_id"=>"17"}
13:51:07 web.1     |   User Load (0.3ms)  SELECT  `users`.* FROM `users` WHERE `users`.`id` = 1 ORDER BY `users`.`id` ASC LIMIT 1
13:51:07 web.1     |   ProjectRequest Load (0.2ms)  SELECT  `project_requests`.* FROM `project_requests` WHERE `project_requests`.`id` = 17 LIMIT 1
13:51:07 web.1     |    (0.1ms)  BEGIN
13:51:07 web.1     |   RequestComment Exists (0.2ms)  SELECT  1 AS one FROM `request_comments` WHERE `request_comments`.`login` IS NULL AND `request_comments`.`request_id` = 17 LIMIT 1
13:51:07 web.1     |    (0.1ms)  COMMIT
13:51:07 web.1     |   Rendering /home/vagrant/.rvm/gems/ruby-2.4.4/gems/smart_listing-1.2.2/app/views/smart_listing/create.js.erb
13:51:08 web.1     |   Rendered /home/vagrant/.rvm/gems/ruby-2.4.4/gems/smart_listing-1.2.2/app/views/smart_listing/create.js.erb (1027.4ms)
13:51:08 web.1     | Completed 500 Internal Server Error in 1200ms (ActiveRecord: 1.0ms)
13:51:08 web.1     | 
13:51:08 web.1     | 
13:51:08 web.1     | 
13:51:08 web.1     | NameError - undefined local variable or method `smart_listing_resource' for #<#<Class:0x00007fbd0dab4358>:0x00007fbce4ed4c90>
13:51:08 web.1     | Did you mean?  smart_listing_render
13:51:08 web.1     |                smart_listing_for:

What am I doing wrong? When I try to use in-place editing on a resource itself (not nested) everything works OK. But with nested resource, I am not able to configure it right,

Kani999 commented 6 years ago