0

I've added JavaScript partials many times before, but admittedly not for a while. The short of it is, I'm missing something stupid.

When I try to render partial 'deleteme.js' at the end of this view:

/app/views/projects/myview.html.slim:

h2 Stuff goes here

render partial: '/projects/thisworks' # Render html partial

render partial: '/projects/deleteme.js' # Render js partial...fails

Which renders this partial:

/app/views/projects/_deleteme.js.erb:

console.log("Oh FFS, Work");

I get:

ActionView::MissingTemplate in Projects#show

Showing /Users/aj/Web/Rails/sh3/app/views/projects/show.html.slim where line #5 raised:

Missing partial /projects/deleteme with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :slim, :jbuilder, :coffee, :haml]}. Searched in: * ...

The incriminating bit is that it's searching for formats => [:html] only, but I thought appending .js automatically tells rails to search for javascript. If anyone has any ideas as to why it's not finding the JS template, I'd be really appreciative. Action code is a very basic:

def show
  @project = Project.find(params[:id])
end

2 Answers 2

1
 /app/views/projects/_deleteme.js.erb:

You are getting partial naming intertwined with Javascript action naming!

 /app/views/projects/deleteme.js.erb:

rename your javascript file, remove the _

You have to make sure your show responds to js

def show
  respond_to do |format|
    format.js
    format.html
  end
end
Sign up to request clarification or add additional context in comments.

3 Comments

Many thanks brad. Good news is the error has now changed to :formats=>[:js], bad news is, error is otherwise the same. Any thoughts?
You have to make sure the controller action is told to respond to AJAX def show respond_to do |format| format.js format.html end
I think you need to edit your original question, and more code, and add the exact errors.
0

You are calling a partial inside a slim template so it expects to find

app/views/projects/_deleteme.js.slim

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.