views:

1480

answers:

3

Using rails3 - I have a project with many tasks. I want to use javascript to build the UI for each task. I figured I could display those tasks on the projects show page by rendering a javascript partial for each. I can't get 'tasks/show' to see tasks/show.js.erb Any ideas?

In projects/show.html.erb

<div id="tasks">
<%= render(:partial => "tasks/show", :collection => @project.tasks) %> 
</div>

tasks/show.js.erb

$("tasks").append(new TaskWidget(task.id))

I get the errors

ActionView::MissingTemplate in Projects#show 

Missing partial tasks/show with {:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml], :formats=>[:html], :locale=>[:en, :en]} in view paths .... around line #13

Thanks

+4  A: 

Shouldn't it be in the file _show.js.erb?

From "Using Partials".

wombleton
A: 

The problem is that in Rails 3 the render from the .js file will only look for files in the form of show.js.erb or show.erb

To get around this, you would either need to create a _show.js.erb file, but since that sort of defeats the purpose of partials, you could alternatively just rename the show.html.erb file to show.erb

This is probably bad practice, though, to make a standard controller action without a type ending (e.g. show.erb)

What I would do if I were you is rename your partial something like _tasks.erb instead of _show.html.erb, and then if you needed a tasks/show.html.erb you could just render the _tasks partial inside of that view.

Michael Waxman