Topic: Rail Routes after upgrade from 2.3.5 to 3.0.10

I'm close to getting my application up and running after upgrading from 2.3.5 to 3.0.10, but I keep getting an error message saying my login route does not exist.  Below is the login controller code & the route code:
Login Controller:

class LoginController < ApplicationController
  layout "trinity_price_comparison"
  before_filter :allowed_admin, :only => [:switch_admin]

  def login
    session[:user_id] = nil
    if request.post?
      user = User.authenticate(params[:username], params[:password])
      if user
        if !user.active
          flash.now[:notice] = "Your account has been disabled, please contact your administrator."
        else
          session[:user_id] = user.id
          session[:user] = user
          session[:admin_flag] = false
          uri = session[:original_uri]
          session[:original_uri] = nil
          if uri != nil
            redirect_to(uri || {:controller => "items", :action => "search"})
          else
            redirect_to :controller => "items", :action => "search"
          end
        end
      else
        flash.now[:notice] = "Invalid username/password combination"
      end
    end
  end

  def logout
    session[:user_id] = nil
    flash[:notice] = "Logged out"
    redirect_to :controller => "items", :action => "search"
  end

  def switch_admin
    session[:admin_flag] = !session[:admin_flag]
    redirect_to :controller => "items", :action => "search"
  end
end

Here are the routes:

Apex::Application.routes.draw do
  resources :cross_references
  resources :uom_conversions
  resources :items
  match 'delete_old_data/delete_data' => "items#delete_data"
  match 'delete_old_data' => "items#delete_old_data"
  match 'pricelist_import' => "items#pricelist_import"
  match 'pricelist_import/match_pricelist_columns' => "items#match_pricelist_columns"
  match 'commit_pricelist' => "items#commit_pricelist"
  match 'pricelist_tool' => "items#pricelist_tool"
  match 'cross_reference_import' => "items#cross_reference_import"
  match 'commit_cross_references' => "items#commit_cross_references"
  match 'import_file/commit_import' => "items#commit_import"
  match 'import_file' => "items#import_file"
  match 'import_file/match_columns' => "items#match_columns"
  match 'set_default_matches' => "items#set_default_matches"
  match 'save_default_matches' => "items#save_default_matches"
  match 'search' => "items#search"
  match 'search/import_search_file' => "items#import_search_file"
  match 'search/import_search_file/pick_search_column' => "items#pick_search_column"
  match 'items/create_uom' => "items#create_uom"
  match 'items/remove_uom/:uom_id' => "items#remove_uom"
  match 'items/show_cross_references/:id' => "items#show_cross_references"

  resources :vendors
  resources :manufacturers
  resources :categories
  resources :sub_categories
  resources :hospitals
  resources :agreements
  resources :users

  match 'users/change_password' => "users#change_password"
  match 'users/update_password'=> "users#update_password"
  match 'logout' => 'login#logout', :as => :logout
  match 'switch_admin' => 'login#switch_admin', :as => :logout

  # The priority is based upon order of creation:
  # first created -> highest priority.
  # Sample of regular route:
  #   match 'products/:id' => 'catalog#view'
  # Keep in mind you can assign values other than :controller and :action

  # Sample of named route:
  #   match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
  # This route can be invoked with purchase_url(:id => product.id)

  # Sample resource route (maps HTTP verbs to controller actions automatically):
  #   resources :products

  # Sample resource route with options:
  #   resources :products do

  #     member do
  #       get 'short'
  #       post 'toggle'
  #     end

  #
  #     collection do
  #       get 'sold'
  #     end

  #   end

  # Sample resource route with sub-resources:
  #   resources :products do
  #     resources :comments, :sales
  #     resource :seller
  #   end


  # Sample resource route with more complex sub-resources
  #   resources :products do
  #     resources :comments
  #     resources :sales do
  #       get 'recent', :on => :collection
  #     end
  #   end

  # Sample resource route within a namespace:
  #   namespace :admin do
  #     # Directs /admin/products/* to Admin::ProductsController
  #     # (app/controllers/admin/products_controller.rb)
  #     resources :products
  #   end

  # You can have the root of your site routed with "root"
  # just remember to delete public/index.html.
  # root :to => 'welcome#index'

  root :to => 'items#search'

  # See how all your routes lay out with "rake routes"

  # This is a legacy wild controller route that's not recommended for RESTful applications.

  # Note: This route will make all actions in every controller accessible via GET requests.

  # match ':controller(/:action(/:id))(.:format)'

  match ':controller/:action/:id'
  match ':controller/:action/:id.:format'

end

Re: Rail Routes after upgrade from 2.3.5 to 3.0.10

Also here are the routes which worked prior to the 3.0 upgrade:

ActionController::Routing::Routes.draw do |map|
  map.resources :uom_conversions
  map.connect 'delete_old_data/delete_data', :controller => "items", :action => "delete_data"
  map.connect 'delete_old_data', :controller => "items", :action => "delete_old_data"
  map.connect 'pricelist_import', :controller => "items", :action => "pricelist_import"
  map.connect 'pricelist_import/match_pricelist_columns', :controller => "items", :action => "match_pricelist_columns"
  map.connect 'commit_pricelist', :controller => "items", :action => "commit_pricelist"
  map.connect 'pricelist_tool', :controller => "items", :action => "pricelist_tool"
  map.connect 'cross_reference_import', :controller => "items", :action => "cross_reference_import"
  map.connect 'commit_cross_references', :controller => "items", :action => "commit_cross_references"
  map.connect 'import_file/commit_import', :controller => "items", :action => "commit_import"
  map.connect 'import_file', :controller => "items", :action => "import_file"
  map.connect 'import_file/match_columns', :controller => "items", :action => "match_columns"
  map.connect 'set_default_matches', :controller => "items", :action => "set_default_matches"
  map.connect 'save_default_matches', :controller => "items", :action => "save_default_matches"
  map.connect 'search', :controller => "items", :action => "search"
  map.connect 'search/import_search_file', :controller => "items", :action => "import_search_file"
  map.connect 'search/import_search_file/pick_search_column', :controller => "items", :action => "pick_search_column"
  map.connect 'items/create_uom', :controller => "items", :action => "create_uom"
  map.connect 'items/remove_uom/:uom_id', :controller => "items", :action => "remove_uom"
  map.connect 'items/show_cross_references/:id', :controller => "items", :action => "show_cross_references"

  
  map.resources :items

  map.resources :vendors

  map.resources :manufacturers

  map.resources :sub_categories

  map.resources :categories

  map.resources :hospitals

  map.resources :ministry_organizations

  map.resources :agreements
  


  map.connect 'users/change_password', :controller => "users", :action => "change_password"
  map.connect 'users/update_password', :controller => "users", :action => "update_password"
  map.resources :users
  
  map.logout '/logout', :controller => 'login', :action => 'logout'
  map.logout '/switch_admin', :controller => 'login', :action => 'switch_admin'

  # The priority is based upon order of creation: first created -> highest priority.

  # Sample of regular route:
  #   map.connect 'products/:id', :controller => 'catalog', :action => 'view'
  # Keep in mind you can assign values other than :controller and :action

  # Sample of named route:
  #   map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase'
  # This route can be invoked with purchase_url(:id => product.id)

  # Sample resource route (maps HTTP verbs to controller actions automatically):
  #   map.resources :products

  # Sample resource route with options:
  #   map.resources :products, :member => { :short => :get, :toggle => :post }, :collection => { :sold => :get }

  # Sample resource route with sub-resources:
  #   map.resources :products, :has_many => [ :comments, :sales ], :has_one => :seller
  
  # Sample resource route with more complex sub-resources
  #   map.resources :products do |products|
  #     products.resources :comments
  #     products.resources :sales, :collection => { :recent => :get }
  #   end

  # Sample resource route within a namespace:
  #   map.namespace :admin do |admin|
  #     # Directs /admin/products/* to Admin::ProductsController (app/controllers/admin/products_controller.rb)
  #     admin.resources :products
  #   end

  # You can have the root of your site routed with map.root -- just remember to delete public/index.html.
  map.root :controller => "items", :action => "search"

  # See how all your routes lay out with "rake routes"

  # Install the default routes as the lowest priority.
  # Note: These default routes make all actions in every controller accessible via GET requests. You should
  # consider removing or commenting them out if you're using named routes and resources.
  map.connect ':controller/:action/:id'
  map.connect ':controller/:action/:id.:format'
end

Last edited by rugburn (2012-07-31 13:49:30)

Re: Rail Routes after upgrade from 2.3.5 to 3.0.10

apparently after some debugging the line of code that is causing the route issues is:

protected
  def authorize
    unless User.find_by_id(session[:user_id])
      session[:original_uri] = request.request_uri              <<<<<<<<<Problem
      #flash[:notice] = "Please log in"
      redirect_to :controller => 'login', :action => 'login'
    end
  end


any idea how to fix it?

Re: Rail Routes after upgrade from 2.3.5 to 3.0.10

Thankyou so much, it really helped alot!!

Re: Rail Routes after upgrade from 2.3.5 to 3.0.10

I changed session[:original_uri =request.path and that issue is fixed, now apparently the redirect no longer works the same in 3.1 as it did in 2.3.5.

Any idea what to change these to get them to work in 3?:

redirect_to :controller => 'login', :action => 'login'
redirect_to :controller => 'items', :action => 'search'