问题
I'm working with a user role based rails application, that will render different views based on a given user role. This is accomplished by using custom mime types. I built it according to this stack overflow post here.
It works brilliantly. You don't even have to explicitly render the according templates in a controller:
def index
@projects = Project.all
end
instead of:
def index
@projects = Project.all
respond_to do |format|
format.html
format.admin
end
end
The controller will automatically render the correct template, thanks to the mime type ending of the file.
The only problem I'm having now is, that my view folder is kinda getting cluttered with all these different templates and I'd like to group and organize them in subfolders according to their type. Let's say I want to create a subfolder named "admin" and put all my admin typed files there. This leads to the files not being found anymore, because the controller doesn't look for them in the subfolder. Therefore I get a template missing error.
Is there any way to organize them in subfolders while keeping my controller clean, i.e. not having to explicitly state the whole path of the template in a render call?
回答1:
I was able to restructure the view folders by changing the default view path like suggested here.
来源:https://stackoverflow.com/questions/10030887/render-mime-typed-templates-in-rails-that-are-in-a-subfolder-without-explicitly