1

I'm updating a Rails app to utilize Ember.js. Those views that existed within the app prior to integrating ember still work fine, but I've also added several new views. These views have all the necessary ember parts (template, controller, etc), as well as all the Rails parts, excluding the view files.

These views work fine if the user accesses them by clicking on an internal link. However, if the user reloads the page or manually enters the URL, then I get this error:

ActionView::MissingTemplate at /contribute
Missing template pages/contribute, application/contribute with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :raw, :ruby, :slim, :coffee]}. Searched in:
  * "/home/sites/whistlr/app/views"
  * "/home/.rvm/gems/ruby-2.0.0-p0@whistlr/gems/devise-3.0.0/app/views"

This is clearly happening because I do not have view files. The question is, is this strictly necessary? Is there some way to tell Rails to just load up the Ember views? Ideally, I'd just delete all the old Rails view files once the conversation is complete.

4

2 回答 2

1

这不是必需的,但是您需要设置 railsroutes.rb以拥有一个捕获所有路由,该路由也像显示 ember 应用程序及其 html 的索引页面一样呈现。

namespace :api do
  # resources go here
end

root :to 'home#index'
match "/*path" => 'home#index'

注意:您想为您的项目自定义此路径模式,否则 404 也会发送到此处。

于 2013-07-25T12:14:29.560 回答
1

没有必要创建单独的视图。诀窍是在应用程序控制器中捕获异常,然后强制它渲染布局:

class ApplicationController < ActionController::Base
  rescue_from ActionView::MissingTemplate do |exception|
    render "/layouts/application"
  end
end
于 2013-09-18T21:39:24.390 回答