Last active
December 21, 2015 12:19
-
-
Save mraaroncruz/6305328 to your computer and use it in GitHub Desktop.
A rails controller to deal with angular templates.
This file contains 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
# Just put your erb, haml, slim, etc. templates in app/views/angular_templates/my_template_name. | |
# For example your templatePath could be `articles/show` and your template | |
# would be app/views/angular_templates/articles/show.html.erb | |
class AngularTemplatesController < ApplicationController | |
def show | |
path = params[:template_path] | |
template_dir = File.join(Rails.root, "app", "views", "angular_templates") | |
templates = Dir.glob("#{template_dir}/**/*").map { |file| | |
file.sub(/.*?\/angular_templates\/(.+)\.html\.slim/, '\1') | |
} | |
if templates.include?(path) | |
render "angular_templates/#{path}", layout: false | |
else | |
render status: :unprocessible_entity, text: "ERROR" | |
end | |
end | |
end |
This file contains 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
MyApp::Application.routes.draw do | |
get "angular_templates/*template_path", to: "angular_templates#show" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment