Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/53.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 使用rails中的form params查找记录;不能';“找不到错误”;_Ruby On Rails_Forms_Ruby On Rails 4_Destroy - Fatal编程技术网

Ruby on rails 使用rails中的form params查找记录;不能';“找不到错误”;

Ruby on rails 使用rails中的form params查找记录;不能';“找不到错误”;,ruby-on-rails,forms,ruby-on-rails-4,destroy,Ruby On Rails,Forms,Ruby On Rails 4,Destroy,我不熟悉rails。我正在尝试使用表单字段中提交的值查找“类别”记录。由于我一直使用Find by params[:id]作为url参数,所以我认为它可以用于表单参数。 这是我的错误 Couldn't find Category with 'id'= on this line: @category = Category.find(params[:category_id]) 这是我的密码 posts\u controller.rb def delete @post = Post.fin

我不熟悉rails。我正在尝试使用表单字段中提交的值查找“类别”记录。由于我一直使用Find by params[:id]作为url参数,所以我认为它可以用于表单参数。

这是我的错误

Couldn't find Category with 'id'=

on this line:

 @category = Category.find(params[:category_id])
这是我的密码

posts\u controller.rb

def delete
  @post = Post.find(params[:id])
  @category = Category.find(@post.category_id)
  @post_archive = PostArchive.new
end

def destroy
 @post = Post.find(params[:id])
 *@category = Category.find(params[:category_id])* <--the error hits here
 @old_id = params[:post_id]
 @author_id = params[:author_id]
 @followers = Follower.find(post_id: @old_id)
 @post_archive = PostArchive.new

 PostArchive.create!(post_id: @old_id, author_id:   @author_id , removed_by: current_user.id,
  category_id: @category.id, 
  post_created_at: @post.created_at )
 @post.destroy

 @followers.each do |follower|
       ProjectMailer.post_deletion(current_user, @category, @author_id, follower, @old_id ).deliver
  end
  @followers.destroy_all
  redirect_to posts_path, notice: 'Project Deleted' 
end
def销毁
@post=post.find(参数[:id])
*@category=category.find(参数[:category_id])*
def destroy
@post=post.find(参数[:id])

*@category=category.find(params[:category\u id])*从参数中可以看到,
category\u id
delete\u post

Parameters: {"delete_post"=>{"author_id"=>"21", "category_id"=>"2", "post_id"=>"417"}, "commit"=>"Delete Post", "id"=>"417"}
应该是

@category = Category.find(params[:delete_post][:category_id])

从参数中可以看到,
category\u id
delete\u post

Parameters: {"delete_post"=>{"author_id"=>"21", "category_id"=>"2", "post_id"=>"417"}, "commit"=>"Delete Post", "id"=>"417"}
应该是

@category = Category.find(params[:delete_post][:category_id])

试试这个
@category=category.find(params[:delete_post][:category_id])
试试这个
@category=category.find(params[:delete_post][:category_id])
谢谢……我看到你在正式答案之前的评论中发布了答案。谢谢……我看到你在正式答案之前的评论中发布了答案。
@category = Category.find(params[:delete_post][:category_id])