5

When I remove respond_to and render to view, everything works fine but adding the js render gives an error.

controller code :

if params[:stock].present?
  @data = params[:stock]
  @stock = Stock.new_form_lookup(params[:stock])
  respond_to do | format |
      format.js  {render partial: 'user/result'} 
  end
else
  flash[:danger] = "no search found "
  redirect_to my_portfolio_path
end

end

View code:

<%= form_tag searchstock_path , remote: true , method: :get, id:"stock-search" do %>

application.js code:

//= rails-ujs
//= require jquery
//= require bootstrap
//= require jquery_ujs
//= require turbolinks
//= require_tree .
Sagar Ahuja
  • 726
  • 6
  • 23
AlmoDev
  • 969
  • 2
  • 18
  • 46

1 Answers1

0

You need to create a file with controller_action_name.js.erb in the view and render the partial their.

$('.className').html("<%= escape_javascript(render 'user/result') %>")
Aditya Tiwari
  • 204
  • 4
  • 17