From: Linda Fay Date: 2011-11-17T23:55:54+09:00 Subject: Help a newbie-The page isn't redirecting properly With good intention I was helping someone with a ruby site but now I've broken it! Yikes. Help please. I made a simple change to the admin controller to add a new action - login2. Making this change caused another action, login, to redirect improperly causing the "page isn't redirecting properly" message using Firefox. Because my change allows me to get to login2 I updated the default page to point to login2 hoping to find a resolve to the redirection problem. No such luck - 2nd problem - can't change the default page for the authorize redirection? Looks simple! (Aside: I spent hours trying to find the issue with why a text change didn't display - turns out it was caching. ugh.) Any help is appreciated! Here's the controller code. class AdminController < ApplicationController before_filter :authorize, :except => [:login, :login2] def authorize if !session[:user] redirect_to :controller => 'admin', :action => 'login2' return false end end def login if request.post? if params[:login] == 'linda' && params[:password] == 'testing' session[:user] = 'yes' redirect_to :controller => 'news', :action => 'index' return end end end def login2 end def logout session[:user] = nil redirect_to :action => 'login2' end def index end def quotes @contacts = Contact.find(:all, :conditions => "quoterequest = 'Yes' AND file is not null") end def destroycontact contact = Contact.find(params[:id]) rescue nil contact.destroy rescue true redirect_to :action => 'quotes' end def contactlist contacts = Contact.find(:all, :conditions => "quoterequest = 'No'") sheet = "Name\tAddress\tCity\tState\tZip\tPhone\tEmail\tComment\tContact Time\tMailing List\tEmail List\n" if contacts && !contacts.empty? for c in contacts sheet += "#{c.name}\t#{c.address}\t#{c.city}\t#{c.state}\t#{c.zip}\t#{c.phone}\t#{c.email}\t#{c.comment.gsub(/[\r\n]/,' ')}\t#{c.created_at}\t#{c.mailinglist}\t#{c.emaillist}\n" end end send_data sheet, :filename => "fsi_contact_list.xls" end def quoterequests contacts = Contact.find(:all, :conditions => "quoterequest = 'Yes' AND file is null") sheet = "Name\tAddress\tCity\tState\tZip\tPhone\tEmail\tComment\tContact Time\tMailing List\tEmail List\n" if contacts && !contacts.empty? for c in contacts sheet += "#{c.name}\t#{c.address}\t#{c.city}\t#{c.state}\t#{c.zip}\t#{c.phone}\t#{c.email}\t#{c.comment.gsub(/[\r\n]/,' ')}\t#{c.created_at}\t#{c.mailinglist}\t#{c.emaillist}\n" end end send_data sheet, :filename => "fsi_quote_requests.xls" end def import file_name = upload(:file) imported = Import.import!(Rails.root.join('public', 'files', file_name).to_s) flash[:notice_admin] = "Succesfully imported #{imported} emails" rescue flash[:notice_admin] = "Could not import specified file. Please check if the file is correct." ensure redirect_to news_index_path end def featured_news_content set_config(:featured_news, params[:featured_news]) flash[:notice_admin] = "Featured News Content Saved" redirect_to news_index_path end def launch_auto_email news = News.not_sent featured_info = get_config(:featured_news) Subscriber.all.each do |s| SystemMailer.deliver_latest_news(s.email, news, featured_info) end # begin # Twitter::Client.new.update(featured_info) # rescue # end # # begin # FbGraph::User.me(FB_ACCESS_TOKEN).feed!( # :message => featured_info # ) # rescue # end flash[:notice_admin] = "Auto Email Launched" redirect_to news_index_path end private def upload(opts, name = "email_database-#{Date.current.to_s}.xls") uploaded_io = params[opts] File.open(Rails.root.join('public', 'files', name), 'w') do |file| file.write(uploaded_io.read) end name end end -- Posted via http://www.ruby-forum.com/.