【发布时间】:2013-11-20 16:28:53
【问题描述】:
我有帖子和帖子类别 帖子属于_to:类别 类别 has_many :posts 我想在创建新帖子时将我重定向到创建的帖子 但是当我在 Posts 控制器中使用时
def create
@category = Category.find(params[:category_id])
@post = current_user.posts.build(post_params)
if @post.save
flash[:success] = "Поздравляем Ваше задание опубликованно"
redirect_to category_post_path(@post)
else
render 'new'
end
end
这个
redirect_to category_post_path(@post)
rails 给我错误
没有路由匹配 {:action=>"show", :controller=>"posts", :category_id=>#, :id=>nil, :format=>nil} 缺少必需的键:[:id]
但我想要@post.save rails redirect_to 创建帖子
请帮忙。
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-4