简体   繁体   中英

Rails ajax respond_to js error

I was following this tutorial , but I encountered some troubles. I got an controller method called sort_new_section , and in the erb , it would use ajax to trigger this controller. Then response to its js.erb and render a partial view.

In create_question_controller

def sort_new_seciton 
...
    @sort_volume = volume
    respond_to do |format|
        format.js   
    end
end

In view/create_question/sort_new_section.js.erb

$('#xxx').append("<%= j render :partial => 'create_question/section_in_panel', :locals => {:volume_id => @sort_volume, } %>");

However, it threw this error.

ActionView::MissingTemplate (Missing template user_create_question/sort_new_seciton, create_question/sort_new_seciton, application/sort_new_seciton with {:locale=>[:"zh-TW", :en], :formats=>[:js, :html], :handlers=>[:erb, :builder, :coffee]}.

The error says sort_new_seciton , not sort_new_section .

ActionView::MissingTemplate (Missing template user_create_question/sort_new_seciton, create_question/sort_new_seciton, application/sort_new_seciton with {:locale=>[:"zh-TW", :en], :formats=>[:js, :html], :handlers=>[:erb, :builder, :coffee]}.

Looks like you have a typo in your code. Specifically, look at your controller method. It's sort_new_seciton .

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