Are you trying to reuse rails partials in the angular app?

This is what I have done in a rails app that uses angular:

in the page (dashboard/index in your case) embed all your angular templates 
in <script type='text/ng-template' id='...'>

I used a helper like = embed_templates %w(app assets javascripts)

module AngularHelper
  def embed_templates(templates_path_or_array)
    templates_root = templates_path_or_array.is_a?(Array) ? 
Rails.root.join(*templates_path_or_array) : 
Rails.root.join(templates_path_or_array)
    templates_path = Pathname(templates_root)
    Pathname.glob(templates_path + '**/*').reject(&:directory?).map do 
|pathname|
      Rails.application.assets[pathname.relative_path_from(templates_path)]
    end.select do |asset|
      # Filter only html templates
      asset.logical_path.split('.').include? 'html'
    end.map do |asset|
      # Remove extra extensions if exist
      content_tag :script, asset.to_s.html_safe, type: 'text/ng-template', 
id: asset.logical_path.split('.')[0..1].join('.')
    end.join("\n").html_safe
  end
end

This will output all you html templates from under app/assets/javascript 
directory as a list of script tags. Then in directives/routes you can refer 
to the templates by their ID
.directive('MyDirective, function(){
   return {
       ...
       templateUrl: 'fonts/font-picker.html'
       ...
}}

For reference: http://docs.angularjs.org/api/ng/service/$templateCache

Regards,
Kliment

On Tuesday, April 8, 2014 5:39:05 PM UTC-4, Steven Harlow wrote:
>
> I've begun integrating AngularJS with an existing Rails application. 
> Everything is set up closely following the Rails way. What I'm curious 
> about, and haven't been able to find information on, is any way to use 
> something like $routeProvider with partials.
>
> For example: If wanted to go to a dashboard page in our Rails only app, 
> we'd hit the dashboard#index controller, which would perhaps render the 
> dashboard/_index.html.slim partial that has various other layouts 
> surronding it (the general application/layout, as well as sidebar layouts 
> and a custom header layout).
>
> In Angular I'd put the template in public/dashboard/index.html, use 
> $routeProvider's templateUrl key, and it would load the whole thing, sans 
> header, sidebar, and application layouts.
>
> *How can I get it to load all the pre-existing layouts that we have 
> already in place?* It'd obviously be much less painful to slowly 
> incorporate $routeProvider and not have to go through and tear out existing 
> architecture.
>
> Also, have any best practices been explored for transitioning a legacy 
> Rails app to use Angular?
>

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to