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

Not sure what changed or if there’s still some kind of caching
problem…

The site now redirects to login2 properly.

And the redirection problem with login is gone.

I wanted to return the site to its original state so I updated the
following:

def authorize
if !session[:user]
redirect_to :controller => ‘admin’, :action => ‘login2’
return false
end
end

to replace login2 with login.

I’m using a text editor and an ftp client.

Caching is turned off - at least in the config file. There are no
caching statements in any of the views or controllers.

Does anyone know why a change takes up to 2 hours to propagate? Am I
missing something on making changes?

Thanks in advance for any help!

On Thu, Nov 17, 2011 at 7:05 AM, Linda F. [email protected] wrote:

Am I missing something on making changes?

Are you just uploading edited files to a running Rails app? Because
if so, yes, you’re missing the way most sites are deployed.

In production mode, the app needs to be restarted to pick up changes;
the normal process is test your changes locally, save to your version
control system (usually git) and then use something like Capistrano to
deploy the updated app to your production server, which gets restarted
in the process.

You should ask whoever created this app how it should be deployed.

HTH,

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs