Render mime typed templates in Rails that are in a subfolder without explicitly providing the whole path in a render call

寵の児 提交于 2019-12-24 17:40:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!