How to change the default path of view files in a Rails 3 controller?

前端 未结 5 2119
甜味超标
甜味超标 2020-12-01 06:16

I have a controller called ProjectsController. Its actions, by default, look for views inside app/views/projects. I\'d like to change that path for

5条回答
  •  日久生厌
    2020-12-01 06:38

    If there's no built-in method for this, perhaps you can override render for that controller?

    class MyController < ApplicationController
      # actions ..
    
      private
    
      def render(*args)
        options = args.extract_options!
        options[:template] = "/mycustomfolder/#{params[:action]}"
        super(*(args << options))
      end
    end
    

    Not sure how well this works out in practice, or if it works at all.

提交回复
热议问题