0

I have a Rails 2.3.5 app with many controllers, models etc. which I'm trying to upgrade to Rails 3.2.21. I'm having some troubles with my routes. I tried to follow the Rails 3 new routing format but it doesn't seem to work. I'm getting two problems (which I guess all indicate one fundamental issue with my routing):

  1. In the root ('/') I'm getting the generic "Welcome abroad" Rails page. My routes (see below) have defined routing for root.
  2. For some controllers I get No route matches [GET] "/study" message. My route shows this route, but for some reason doesn't define the GET method.

Here's my config/routes.rb code:

Myapp::Application.routes.draw do    
  root :to => 'study#index'

  match 'login' => 'login', :protocol => 'https://'

  resources :study_maps do
    get :clone, :on => :member
  end

  # Route report create actions to the report controller
  match 'report/create', :as => 'report'

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

If I'm running rake routes I'm getting:

           root        /                                      study#index
          login        /login(.:format)                       login#login {:protocol=>"https://"}
clone_study_map GET    /study_maps/:id/clone(.:format)        study_maps#clone
     study_maps GET    /study_maps(.:format)                  study_maps#index
                POST   /study_maps(.:format)                  study_maps#create
  new_study_map GET    /study_maps/new(.:format)              study_maps#new
 edit_study_map GET    /study_maps/:id/edit(.:format)         study_maps#edit
      study_map GET    /study_maps/:id(.:format)              study_maps#show
                PUT    /study_maps/:id(.:format)              study_maps#update
                DELETE /study_maps/:id(.:format)              study_maps#destroy
         report        /report/create(.:format)               report#create
                       /:controller(/:action(/:id))(.:format) :controller#:action

Here's my StudyController#index code:

require 'myapp/studymgr'
require 'project_user'
require_dependency 'myapp/controller_extensions/report_manager'

class StudyController < ApplicationController
  include PaginatorController

  before_filter(:authenticate, :except => [:todo])
  before_filter(:authorize,
                :only => [:update, :destroy, :edit, :prune, :select_experiments ])

  def index
    @tags = Stag.find(:all).collect { |stag| stag.tag }
    ...
    @include_ext = true
  end
end

Can someone advise on what I'm missing?

shalomi
  • 1
  • 2
  • I don't see where you've defined routes for the `StudyController`. For `StudyMapsController`, you'll need to post that code for us to help figure out why that is not getting initialized. – steve klein Jul 15 '15 at 22:20
  • For routes you see the StudyMapsController is defined, and there's also a general route that should cover StudyController as well. Do you mean the actual controllers code? – shalomi Jul 15 '15 at 22:25
  • Yes I would suggest you post the code for the `StudyMapsController`. I see the general route now but have never see `match` used that way. It seems to be the root of your issue with the `Study` actions (no pun intended). – steve klein Jul 15 '15 at 22:31
  • I resolved the `StudyMapsController` issue - the name from the old app was `StudyMapController`. My bad... I added the `StudyController` code. Tried to change that (and the routes) to `StudiesController`, but it didn't help. Also, can you please elaborate more on the default `match` usage? How would you suggest to write it? I also tried the default format provided with Rails 3 installation (using rails_upgrade plugin): `match ':controller/:action/:id'` but got the same exact result. – shalomi Jul 16 '15 at 16:39
  • I would define the study routes you need explicitly or use `resources :studies` to get all Restful routes for the Study model. When you make manual changes to fix pluralization issues, use `grep` to make sure you catch all of the changes and double check all folder names. Remember of course to restart your server after changes. – steve klein Jul 16 '15 at 19:45
  • Thanks Steve. I can of course write explicit resource for each model. The issue is that I have >30 models/controllers, and all of them work in the same simple manner of controller#action - isn't that something the default routing should take care of? – shalomi Jul 16 '15 at 23:06

1 Answers1

0

Finally found a solution - my views had .rhtml extension. I found that this format is no longer supported under Rails 3 (What is the difference Between .erb , .rhtml and .html.erb?), so I changed all views extensions to .html.erb and then the routes worked with no need to specify explicit resource for each controller, just using the generic route: match ':controller(/:action(/:id))'.

As for the issue in the root route (#1 above), where I always got the Rails "Welcome abroad" page, despite having explicit route in my routes.rb, turns out I had to remove public/index.html which is loaded for root by Rails, and then my view was loaded.

Community
  • 1
  • 1
shalomi
  • 1
  • 2