简体   繁体   中英

ActionController::UnknownFormat when add respond_to

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 .

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') %>")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM