I am showing a bit of js.erb that allows the ajax function to like / dislike a dish in a restaurant. I recently ran into a callback around_action , and the yield figure helped to first execute the controller action and display the second template. Unfortunately, I get 500 (Internal Server Error) due to the fact that respond_to never called.
The respond_to method works if I put it inside the controller action, but not inside the callback. What am I doing wrong?
class DishesController < ApplicationController before_action :set_dish_and_restaurant around_action :render_vote_partial def like @dish.liked_by current_user end ... private def set_dish_and_restaurant @dish = Dish.find(params[:id]) end def render_vote_partial yield respond_to { |format| format.js { render "vote.js.erb" } } end end
Console error
ActionView::MissingTemplate (Missing template dishes/like, application/like with {:locale=>[:en], :formats=>[:js, "application/ecmascript", "application/x-ecmascript", :html, :text, :js, :css, :ics, :csv, :vcf, :png, :jpeg, :gif, :bmp, :tiff, :mpeg, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json, :pdf, :zip], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}. Searched in: * "/app/views" * "/Library/Ruby/Gems/2.0.0/gems/devise-3.5.1/app/views" ): app/controllers/dishes_controller.rb:29:in `render_vote_partial'