操作控制器::轨道中的未知格式错误



每当我尝试创建新帖子时,都会收到此错误。

操作控制器::轨道中的未知格式错误

class PostsController < ApplicationController
def new
@post = Post.new
end
def create
@post = Post.new(post_params)
@post.user_id = current_user.id
respond_to do |f|
if(@post.save)
f.html  {redirect_to "", notice: "Post Created!"}
else 
# f.html {redirect_to "", notice: "Error! Post not saved"}
end
end
end
private 
def post_params #allows certain data to be passed via post form
params.require(:post).permit(:user_id, :create)
end
end

Rails告诉我,错误发生在第15行的respond_to块中。

Rails服务器是这么说的:

2017-07-30 03:57:59 +0000 为 24.188.104.188 启动 POST "/posts" 无法从 24.188.104.188 渲染控制台!允许的网络: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255 由 PostsController#create as HTML 参数处理: {"utf8"=>"✓", "authenticity_token"=>"+0rkRgEUi9BvIgLyRyxh7wr3VVr5F3HpgoMQVKcwrTmn9tNB6xkKNx+EpxPt7l0NA4sv/lsjmwjn0ROh1gre4A==", "post"=>{"content"=>"hohoh"}, "commit"=>"Add post"} 不允许 参数:内容 用户负载(0.2ms( 选择"用户"。 从"用户" 哪里"用户"。id" = ? 按"用户"排序。id" ASC 限制 1 [["id", 2]] (0.1ms( 开始事务 (0.1ms( 回滚事务已重定向 到 https://bump-jshariar.c9users.io 完成 302 在 21ms 内找到 (活动记录:0.3 毫秒(

在 2017-07-30 03:57:59 +0000 无法为 24.188.104.188 启动 GET "/" 从 24.188.104.188 渲染控制台!允许的网络: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255 由 PagesController#index 作为 HTML 进行处理 布局/应用程序中呈现的页面/索引.html.erb (
0.4ms(用户加载 (0.1ms( 选择"用户"。id" = ? 按"用户"排序。id" ASC 限制 1 [["id", 2]] 呈现 layouts/_nav_user.html.erb (0.3ms( Renders/_nav.html.erb (2.0毫秒( 在 73 毫秒内完成 200 OK (观看次数: 72.5 毫秒 |活动记录:0.1毫秒(

它适用于:

class PostsController < ApplicationController
def new
@post = Post.new
end
def create
@post = Post.new(post_params)
@post.user_id = current_user.id
respond_to do |f|
if(@post.save)
f.html  { redirect_to "", notice: "Post Created!" }
else 
# f.html { redirect_to '' }
end
end
end
private 
def post_params #allows certain data to be passed via post form
params.require(:post).permit(:user_id, :content)
end
end

最新更新