当我删除respond_to
和render to view
时,一切正常,但是添加js render
会出错。
控制器代码:
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
结束
查看代码:
<%= form_tag searchstock_path , remote: true , method: :get, id:"stock-search" do %>
application.js代码:
//= rails-ujs
//= require jquery
//= require bootstrap
//= require jquery_ujs
//= require turbolinks
//= require_tree .
答案 0 :(得分:0)
您需要使用视图中的controller_action_name.js.erb
创建一个文件并将其部分呈现。
$('.className').html("<%= escape_javascript(render 'user/result') %>")