Last active
August 29, 2015 14:07
-
-
Save jacoyutorius/4bf234cb275a40627d64 to your computer and use it in GitHub Desktop.
Controllerを作らずにViewを表示したい ref: http://qiita.com/jacoyutorius/items/97cf87d36807d00b883b
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class AnonymousController < ApplicationController | |
| def index | |
| render "#{params[:directory]}/index" | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| mkdir app/views/foo | |
| touch app/views/foo/index.html.erb | |
| mkdir app/views/bar | |
| touch app/views/bar/index.html.erb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ rake routes | |
| Prefix Verb URI Pattern Controller#Action | |
| bar GET /bar(.:format) anonymous#index {:directory=>"bar"} | |
| foo GET /foo(.:format) anonymous#index {:directory=>"foo"} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| NoControllerApp::Application.routes.draw do | |
| exclude_dir = ["layouts"] | |
| anonymous_dir = [] | |
| Dir::glob(File.join(Rails.root.to_s, "/app/views/*/")).map{|f| anonymous_dir << f.split("/").last } | |
| (anonymous_dir - exclude_dir).each do |dir| | |
| get "#{dir}" => "anonymous#index", :defaults => {:directory => "#{dir}"} | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment