在config/routes.rb
我写的如下
resources :scrapped_movies do
get :check_match
end
基本上,Rails发送到get
后显示但是,我只想将其重定向到索引
在控制器中,
def check_match
type = params[:type]
crawl_id = params[:k1]
watcha_id = params[:k2]
# save params to redis
end
check_match只需要参数,我不必实际显示这个,所以我想返回索引。我怎样才能做到这一点?
如果我只是将redirect_to
放入check_match函数中,Rails
就会发现没有show
错误。
答案 0 :(得分:0)
render :show
和redirect_to
做了很多不同的事情。
render :show
呈现名为show的模板,它将根据控制器名称(app/views/scrapped_movies/show.html.{erb|slim|haml}
)查找模板。并将其作为响应主体返回。
redirect_to action: :show, id: 1
通过发送302 Found
状态重定向浏览器,并将位置标头设置为/scrapped_movies/1
。
此外,Rails中的show动作用于显示单个资源。你想要的很可能是索引:
redirect_to action: :index
# or
redirect_to scrapped_movies_path