ruby - Rails route going to wrong controller action only when there is a rescue_from -


i trying add simple api existing rails 3.2 web app (using this guide). running issue route executing existing action instead of new 1 if try rescue_from exception. here's code (obviously not real code, keeps essential elements):

# config/routes.rb  resources :merchants, only: [:index] # existing route # rake routes generates: goodies /goodies(.:format) goodies#index  # http://railscasts.com/episodes/350-rest-api-versioning class apiconstraints   def initialize(options)     @version = options[:version]     @default = options[:default]   end    def matches?(req)     req.headers['accept'].include?("application/vnd.my_app.v#{@version}") || @default   end end  namespace :api, defaults: { format: 'json' }   scope module: :v1, constraints: apiconstraints.new(version: 1)     resources :goodies, only: [:index] # new route   end end # rake routes generates: api_goodies /api/goodies(.:format) api/v1/goodies#index {:format=>"json"} 

.

# app/controllers/goodies_controller.rb  class goodiescontroller < applicationcontroller   def index     @goodies = goody.order(:name)   end end 

.

# app/controllers/api/v1/base_controller.rb  class api::v1::basecontroller < actioncontroller::metal   include actioncontroller::rendering   include actioncontroller::mimeresponds   include abstractcontroller::callbacks    append_view_path "#{rails.root}/app/views"    before_filter :authenticate   rescue_from notauthenticated, :deny_access # works if comment-out line    private    def authenticate     # fail notauthenticated if not authenticated   end    def deny_access     render json: { error_message: 'forbidden' }, status: 403   end end 

.

# app/controllers/api/v1/goodies_controller.rb  class api::v1::goodiescontroller < api::v1::basecontroller   def index     @goodies = goody.order(:name)   end end 

here scenarios when send get my_app.dev/api/goodies request has accept header value set application/vnd.my_app.v1:

  1. (with rescue_from)
    1. without auth creds - results view used goodies#index instead of 1 used api/v1/goodies#index
    2. with auth creds - same
  2. (without rescue_from)
    1. without auth creds - standard development rails 500 error page showing notauthenticated error raised
    2. with auth creds - results view used api/v1/goodies#index

for scenario #1, know it's not using wrong view because if put fail in api/v1/goodies#index, still results goodies#index.

i don't think relevant, i'm using *.json.jbuilder views.

i saw this post, similar, specific rescue_from. haven't tried op's comment, don't think should have change controller name make work.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

jquery - Keeping Kendo Datepicker in min/max range -