How do you render a different .js.erb
file while using Ajax?
For example:
<% form_tag user_path, :method => :get, :remote => true do %>
This goes through the UserController#show
and then renders users/show.js.erb
. How do I make it go through the UserController#show
and then render users/hello.js.erb
?
In users_controller.rb:
def show
@user = User.find(params[:id])
respond_to do |format|
format.js { render 'hello.js.erb' }
end
end
or shorter as there is only one respond format:
def show
@user = User.find(params[:id])
render :hello
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With