Reputation: 295
In my application i have comments which are creating without reloading.
comments_controller
def create
...
@comment.save
respond_to do |format|
format.html
format.js
end
end
create.js.erb
$("#id").html("<%= escape_javascript(render(:partial => @comments)) %>");
Comments can be posted on two pages, both of these two pages use create.js.erb. I want only first page use create,js,erb, and another page use anothercreate.js.erb How can i do that? Thanks in advance!
Upvotes: 0
Views: 147
Reputation: 4802
You can use render
to specify which view you want rendered
respond_to do |format|
format.html
format.js {render "anothercreate.js.erb" }
end
This link has more info on rendering, and all the different ways you can write the call to render
to get it to use the correct view: http://guides.rubyonrails.org/layouts_and_rendering.html
Upvotes: 1