I have began playing with Rails 3 beta and I am trying to do my usual starter project. I create a simple list of projects, but use ajax requests for the app's navigation. In Rails 3, my usual code does not work for the basic scaffold, I receive an
ActionView:MissingTemplate (Missing template projects/new with {:format=>[:js]}
Here is my a snippit from my projects controller:
# GET /projects/new
# GET /projects/new.xml
def new
@project = Project.new
respond_to do |format|
format.html # new.html.erb
format.js { render :layout => false }
format.xml { render :xml => @project }
end
end
Notice the format.js line. I use the Mootools library for my javascript and I have not yet tried out the new unobtursive hooks that rails 3 provides, so I still write it by hand. Here is the javascript request that fires when the 'new' link is clicked on the page. In Mootools, the Request.HTML update attributes updates the div I have in the HTML with the id 'main'.
a.addEvents({
'click': function(e) {
e.stop();
console.log("Click for '" + a.get('href') + "'");
new Request.HTML({
url: a.get('href'),
method: 'get',
update: 'main',
onRequest: function() {},
onSuccess: function() {},
onFailure: function(xhr) {},
onComplete: function() {}
}).send();
}
});
So what is happening when the link is clicked, is the controller tries to respond to the js call with the new.js.erb file, which I don't have. In previous versions of rails, this would not be the case and it would respond back with the new.html.erb automatically. If I remove the format.js line in the controller, it responds back, but I don't want the response to have layout when called through javascript.
Is there something that changed in Rails 3 beta?