Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Render different .js file with Rails Ajax

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?

like image 834
Dol Avatar asked Feb 07 '12 03:02

Dol


1 Answers

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
like image 156
Patrick Klingemann Avatar answered Sep 30 '22 05:09

Patrick Klingemann