Reputation: 5682
Stumped here, on our website we have an FAQ, on the admin side we have the ability to add/edit/delete FAQ categories and individual FAQ's inside those categories.
In my faq_controller I have these 2 methods:
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
This line:
redirect_to "/faq_categories/#{params[:faq_category_id]}"
Used to be:
redirect_to :back
but that wasn't working to I switched to the more explicit path but no matter what I do it won't destroy the faq.
My server log says this:
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)
The weirdest thing about this though is that it works on my local machine. My local log looks like this:
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)
Which is correct so...
TL:DR Why is this redirect_to
not working on my staging server, and what exactly does the filter chain halted as :redirect_to_https
line mean?
Upvotes: 2
Views: 2007
Reputation: 4636
May be you set HTTPS in your production config file but not development config file.
Say your controller is called faq_categories, and the method is called show
You can do it by:
class faq_categories_Controller
skip_filter :redirect_to_https
end
which will prevent the HTTPS checking
Or you can do it by:
redirect_to {:protocol => 'https://', :controller => 'faq_categories', :action => 'show'}
Upvotes: 1
Reputation: 5682
The site was already using https, so I still don't know why the filter chain was breaking but @code4j started me in the right direction.
Adding this to my faq_controller fixed the problem:
skip_filter :redirect_to_https
Upvotes: 0