Reputation: 1527
Is it possible to render only Javascript file instead of HTML for Rails action.
For example action 'index':
def index
@products = Product.all
end
I would like the file "index.js.erb" to be called instead of "index.html.erb".
Upvotes: 1
Views: 609
Reputation: 3633
Use respond_to .
def index
@products = Product.all
respond_to do |format|
format.js
end
end
This means client can only ask for JS response. More about MimeResponds
Upvotes: 1