# Responding with JS
respond_to do |format|
if @review.save
format.html { redirect_to @restaurant, notice: "yes" }
# redirect_to @restaurant
format.js # Returning JS as well
else
format.html { render action: new }
format.js # Returning JS as well
# render :new
end
# Responding with a custom JS file
format.js { render :custom_create }
# Responding with JS based on a condition
format.js { render false ? :custom_create : :create } # Uses ternary operator
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter