skip to Main Content

I am trying to display the results of a SHOW action using AJAX.

in the show.js.erb, this renders properly:

$('#someid').html("<p>regular html</p>")

and this renders the name of the selected @category

$('#someid').html("<%= j render @categories %>")

but does not work when trying to render the associated SHOW view (show.html.erb):

$('#someid').html("<%= j render 'show', category: @category %>")

the errors i recieve is as follows:

ActionView::Template::Error (Missing partial categories/_show with {:locale=>[:en], :formats=>[:js, :html, :text, :css, :ics, :csv, :vcf, :vtt, :png, :jpeg, :gif, :bmp, :tiff, :svg, :mpeg, :mp3, :ogg, :m4a, :webm, :mp4, :otf, :ttf, :woff, :woff2, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json, :pdf, :zip, :gzip], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby, :jbuilder]}. Searched in:
  * "/home/ubuntu/environment/project_name/app/views"
  * "/home/ubuntu/.rvm/gems/ruby-2.6.3/gems/actiontext-6.0.3/app/views"
  * "/home/ubuntu/.rvm/gems/ruby-2.6.3/gems/actionmailbox-6.0.3/app/views"
):
    1: $('#someid').html("<%= j render 'show', category: @category %>")
  
app/views/categories/show.js.erb:1

what can I do to render show.html.erb?

2

Answers


  1. you should change folder show.html.erb -> _show.html.erb
    because it is templale partial to render

    Login or Signup to reply.
  2. Answer on the behalf of OP:

    The issue, in the end, was that the show.html.erb needed to be named
    _show.html.erb

    I was looking at the browser errors and not the rails server errors. I
    posted the errors still, to document my solving process.

    I was able to see that in this line in the error

    ActionView::Template::Error (Missing partial categories/_show with {:locale=>[:en], .......
    

    Had the underscore before show.html.erb, something not immediately
    apparent to me upon using AJAX for the first time.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search