2

在这里难住了,在我们的网站上,我们有一个常见问题解答,在管理方面,我们可以添加/编辑/删除常见问题解答类别和这些类别中的单个常见问题解答。

在我的 faq_controller 我有这两种方法:

def destroy
  faq = load_faq_for_faq_category
  faq.destroy if faq
  redirect_to "/faq_categories/#{params[:faq_category_id]}"
end

private

def load_faq_for_faq_category
  faq = Faq.where(:id => params[:id]).first!

  if faq.faq_category_id != params[:faq_category_id].to_i
    raise ActiveRecord::RecordNotFound, "FAQ doesn't belong to specified FAQ Category"
  end
  faq
end

这一行:

redirect_to "/faq_categories/#{params[:faq_category_id]}"

以前是:

redirect_to :back

但这对我不起作用,我切换到更明确的路径,但无论我做什么,它都不会破坏常见问题解答。

我的服务器日志这样说:

Started DELETE "/faq_categories/4/faq/50" at 2012-12-19 15:44:32 +0000
Processing by FaqController#destroy as HTML
Parameters: {"faq_category_id"=>"4", "id"=>"50"}
Redirected to http://my_staging_server/faq_categories/4/faq/50
Filter chain halted as :redirect_to_https rendered or redirected
Completed 302 Found in 1ms (ActiveRecord: 0.0ms)

不过,最奇怪的是它可以在我的本地机器上运行。我的本地日志如下所示:

Started DELETE "/faq_categories/1/faq/5" for 127.0.0.1 at 2012-12-19 09:03:05 -0700
Processing by FaqController#destroy as HTML
Parameters: {"faq_category_id"=>"1", "id"=>"5"}
User Load (0.2ms)  SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1
Role Exists (0.1ms)  SELECT 1 AS one FROM `roles` INNER JOIN `roles_users` ON `roles`.`id` = `roles_users`.`role_id` WHERE `roles_users`.`user_id` = 1 AND `roles`.`lookup_code` = 'root' LIMIT 1
Faq Load (0.1ms)  SELECT `faqs`.* FROM `faqs` WHERE `faqs`.`id` = 5 LIMIT 1
(0.2ms)  BEGIN
CACHE (0.0ms)  SELECT `faqs`.* FROM `faqs` WHERE `faqs`.`id` = 5 LIMIT 1
SQL (0.2ms)  DELETE FROM `faqs` WHERE `faqs`.`id` = 5
SQL (0.3ms)  UPDATE `faqs` SET position = (position - 1) WHERE (`faq_category_id` = 1 AND position > 1)
(45.1ms)  COMMIT
Redirected to http://localhost:3000/faq_categories/1
Completed 302 Found in 54ms (ActiveRecord: 46.3ms)

哪个是正确的所以...

TL:DR为什么这redirect_to在我的登台服务器上不起作用,这filter chain halted as :redirect_to_https条线到底是什么意思?

4

2 回答 2

1

可能是您在生产配置文件中设置了HTTPS,但没有在开发配置文件中设置。

假设您的控制器称为faq_categories,该方法称为show

你可以这样做:

class faq_categories_Controller
    skip_filter :redirect_to_https
end

这将阻止 HTTPS 检查

或者你可以这样做:

redirect_to {:protocol => 'https://', :controller => 'faq_categories', :action => 'show'}
于 2012-12-19T18:06:25.620 回答
0

该网站已经在使用 https,所以我仍然不知道为什么过滤器链会中断,但 @code4j 让我朝着正确的方向前进。

将此添加到我的 faq_controller 解决了问题:

skip_filter :redirect_to_https
于 2012-12-19T18:39:40.453 回答