当添加response_to时,ActionController :: UnknownFormat

时间:2019-09-29 21:42:45

标签: javascript ajax ruby-on-rails-5.2

当我删除respond_torender 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 .

1 个答案:

答案 0 :(得分:0)

您需要使用视图中的controller_action_name.js.erb创建一个文件并将其部分呈现。

$('.className').html("<%= escape_javascript(render 'user/result') %>")