small medium large xlarge

01 Feb 2011, 11:46
Stuart John Ackland (9 posts)

I have been working through the third edition version: 2009-2-26 P1.0 printing March 2009. and I can’t seem to get past a 500 error that keeps popping up in my Browser.

Normally when I have a problem it turns out to be a typo on my part so please be assured that I have gone over the code I have typed thoroughly. I have also copied and pasted the code from the .pdf version I have of the book. So although there may well be an error in the code, I don’t believe it to be a typo from me copying from the book.

At the end of page 189 all is working absolutely fine. The drop down language selection form is displaying properly and functioning at the top of the ‘Store’ page when viewed. However once I edit app/controllers/application.rb I receive the following error.

We’re sorry, but something went wrong. We’ve been notified about this issue and we’ll take a look at it shortly.

I have checked by rolling this code back and it works again, I carried on coding until the end of page 192 to see if things would correct themselves but unfortunately it doesn’t change a thing. So I think it has to be an error within the controller.

Below is a copy of this file as I have it saved. Can anyone highlight my error or help me better understand what might be going on here so that I can correct it and carry on muddling through in the hope that I might actually learn something in the end!! ` # Filters added to this controller apply to all controllers in the application. # Likewise, all the methods added will be available for all controllers. class ApplicationController < ActionController::Base layout “store” before_filter :authorize, :except => :login before_filter :set_locale #… helper :all # include all helpers, all the time protect_from_forgery # See ActionController::RequestForgeryProtection for details # Scrub sensitive parameters from your log # filter_parameter_logging :password`

protected def set_locale session[:locale] = params[:locale] if params[:locale] I18n.locale = session[:locale] || I18n.default_locale locale_path = "#{LOCALES_DIRECTORY}#{I18n.locale}.yml" unless I18n.load_path.include? locale_path I18n.load_path << locale_path I18n.backend.send(:init_translations) end rescue Exception => err logger.error err[:notice] = "#{I18n.locale} translation not available" I18n.load_path -= [locale_path] I18n.locale = session[:locale] = I18n.default_locale end end

def authorize unless User.find_by_id(session[:user_id]) flash[:notice] = "Please log in" redirect_to :controller => 'admin', :action => 'login' end end


You must be logged in to comment