javascript - 找不到 SomeController#create 渲染头的模板:no_content
问题描述
我正在构建一个 Rails 应用程序,该应用程序创建一个喜欢(创建)或不同(销毁),在链接上单击远程:真正的 ajax 请求
帖子通过并提交了事务,但 js 响应没有通过,我在服务器控制台中收到错误
No template found for ForumThreads::ForumPosts::LikesController#create, head :no_content
视图结构是
forum_threds/show.html.haml
....
= render @forum_thread.forum_posts
....
呈现线程中每个帖子的视图
forum_posts/_forum_post.html.haml
....
%div{id: "fourm_post_#{forum_post.id}" }
= render partial: "forum_posts/likes", locals: { post: forum_post }
....
这是渲染
forum_posts/_likes.html.haml
- if user_signed_in? && current_user.likes?(post)
= link_to "UnLike", forum_post_likes_path(post), method: :delete,
remote: true
- else
= link_to "Like", forum_post_likes_path(post), method: :post, remote:
true
我的控制器是
class ForumThreads::ForumPosts::LikesController < ApplicationController
before_action :authenticate_user!
before_action :set_forum_post
before_action :set_forum_thread
def create
@forum_post.likes.where(user_id: current_user.id).first_or_create
respond_to do |format|
format.js
format.html { redirect_to @forum_thread}
end
end
def destroy
@forum_post.likes.where(user_id: current_user.id).destroy_all
respond_to do |format|
format.js
format.html { redirect_to @forum_thread}
end
end
private
def set_forum_thread
@forum_thread = ForumThread.find(@forum_post.forum_thread_id)
end
def set_forum_post
@forum_post = ForumPost.find(params[:forum_post_id])
end
end
使用 remote: false 这在页面重新加载时按预期工作,但是当我放 remote: true 时,我收到没有模板错误
我的视图文件结构
- 论坛线程/
- 显示.html.haml
- 论坛帖子/
- 显示.html.haml
- _likes.html.haml
- 喜欢/
- 创建.js.erb
- 销毁.js.erb
以及 create.js.erb 和 destroy.js.erb
$("#forum_post_<%= forum_post.id %>").html(<%= j render
'forum_posts/likes' %>);
但我知道这个文件甚至没有被调用
有没有一种方法可以从 format.js 中直接调用我需要的文件?或者其他的东西?
解决方案
推荐阅读
- html - Bootstrap 列不相邻显示
- typo3 - 从 TCA 错字3 中的 crdate 中删除小时、分钟和秒
- mongodb - 如何在 mongoDb 中进行过滤?
- javascript - 为什么添加后无法访问数组的项目?
- sql-server - SQL Server 中多行的逗号分隔值
- reactjs - Laravel Passport 可以与 PostMan 一起使用,但不能与 APP 一起使用?
- java - 将数据库中的数据以Java的形式输出给用户
- sql - 如何使用下一个日期列值来计算当前列的增量
- angular - Angular Schematics:trustedSubscriber._addParentTeardownLogic
- php - 问题比较php中的值