Chrome browser can't find partial
I use the following in my controller to add tasks to my project model using ajax.
def task_add
project = Project.find(params[:project])
@task = ProjectTask.new(:description => params[:description])
project.project_ta开发者_如何学Pythonsks << @task
render :partial => 'task'
end
and my ajax call:
$('#task-add').click(function(){
var taskDesc = $('#task-description').val();
$.ajax({
type: "POST",
url: "/project_task_add",
data: ({project:<%= @project.id %>, description:taskDesc}),
success: function(data){
var data = $('<div/>').append(data);
$('#tasks').append($('#new-task', data).html());
}
});
});
It works fine in Firefox but Chrome gives the following error:
Failed to load resource: the server responded with a status of 500 (Internal Server Error)
Digging deeper in the chrome dev tools I find the following response:
<h1>Template is missing</h1>
<p>Missing partial projects/task with {:locale=>[:en, :en], :formats=>[:js, :"*/*"], :handlers=>[:erb, :rjs, :rhtml, :builder, :rxml]} in view paths "/home/user/apps/my_app/app/views", "/usr/lib/ruby/gems/1.8/gems/devise-1.1.5/app/views"</p>
The _task.html.erb partial exists under /views/projects/ and Firefox renders it just fine. I don't understand what's different in Chrome... any ideas?
the method of the request is :js. I think rails is try to render _task.js.rjs not _task.html.erb . You could explicit It
render :partial => 'projects/task.html.erb'
but i think that you could change the view from wich request is generated so that they dont have params method js Or render an ajax response.
post your view if you want more help!
This is expecting your partial to be called app/views/projects/task.js.erb
(as figured out by the formats
part of your error, not app/views/projects/task.html.erb
. You probably only have the html
partial defined.
精彩评论