PlankTon
PlankTon

Reputation: 12605

Rails partials not picking up javascript format

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

Upvotes: 0

Views: 894

Answers (2)

RadBrad
RadBrad

Reputation: 7304

 /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

Upvotes: 1

jvnill
jvnill

Reputation: 29599

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

app/views/projects/_deleteme.js.slim

Upvotes: 0

Related Questions