Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined local variable or method `smart_listing_resource' #151

Closed
Kani999 opened this issue Sep 6, 2018 · 1 comment
Closed

Undefined local variable or method `smart_listing_resource' #151

Kani999 opened this issue Sep 6, 2018 · 1 comment

Comments

@Kani999
Copy link

Kani999 commented Sep 6, 2018

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_requests_controller.rb

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


app/views/project_requests/show.html.haml

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

app/views/request_comments/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/request_comments/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/request_comments/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
Copy link
Author

Kani999 commented Sep 7, 2018

  • Problem was in the name of file - js.rb instead js.erb

@Kani999 Kani999 closed this as completed Sep 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant