Is it possible to render a js.erb in response to an AJAX request without using the respond_to
method?
I am asking because of a few reasons:
- I will only be making AJAX calls to my controllers;
- I will not be supporting any other content types (i.e., :html, :xml, etc.); and
- I want to be able to render a different
js.erb
file, not one named the same as the controller method (i.e.,different.js.erb
)
Here is some code to serve as an example.
app/views/posts/awesome.js.erb:
alert("WOOHOO");
PostsController#create
def create
@post = Post.new(params[:task])
if @post.save
render :partial => 'awesome.js.erb'
end
end
When the create
method is called via AJAX, Rails complains about a partial missing:
ActionView::MissingTemplate (Missing partial post/awesome.js, application/awesome.js with {:handlers=>[:erb, :builder, :coffee, :haml], :formats=>[:js, "application/ecmascript", "application/x-ecmascript", :html, :text, :js, :css, :ics, :csv, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json], :locale=>[:en, :en]}. Searched in: