Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何修复Rails中的此Ember CLI错误?_Ruby On Rails_Ruby On Rails 4_Ember.js_Ember Cli_Ruby On Rails 4.2 - Fatal编程技术网

Ruby on rails 如何修复Rails中的此Ember CLI错误?

Ruby on rails 如何修复Rails中的此Ember CLI错误?,ruby-on-rails,ruby-on-rails-4,ember.js,ember-cli,ruby-on-rails-4.2,Ruby On Rails,Ruby On Rails 4,Ember.js,Ember Cli,Ruby On Rails 4.2,我正在Rails项目中集成我的第一个Ember应用程序。我已经添加了ember cli railsgem并运行了初始化程序,因此我有一个config/initializers/ember.rb文件,如下所示: EmberCLI.configure do |c| c.app :products, path: 'products' end 我的Ember应用程序位于我的Rails应用程序根目录中,名为products。目前,除了生成默认的余烬应用程序,我什么也没做 我已经在Rails中为Pro

我正在Rails项目中集成我的第一个
Ember
应用程序。我已经添加了
ember cli rails
gem并运行了初始化程序,因此我有一个
config/initializers/ember.rb
文件,如下所示:

EmberCLI.configure do |c|
  c.app :products, path: 'products'
end
我的Ember应用程序位于我的Rails应用程序根目录中,名为
products
。目前,除了生成默认的余烬应用程序,我什么也没做

我已经在Rails中为
ProductsController
创建了一个特定的布局。它是app/views/products.html.erb。我添加了以下行:

<%= include_ember_script_tags :products %>
<%= include_ember_stylesheet_tags :products %>
最后,我在我的Ember应用程序中更改了
config/environments.js

var ENV = {
  modulePrefix: 'products',
  environment: environment,
  baseURL: '/products', // changed from '/' to '/products'
  locationType: 'auto',
  EmberENV: {
    FEATURES: {
      // Here you can enable experimental features on an ember canary build
      // e.g. 'with-controller': true
    }
  },
该控制器的索引页显示良好。它正在尝试加载余烬文件,但我收到一个错误:

Uncaught Error: Assertion Failed: rootURL must end with a trailing forward slash e.g. "/app/"
ember cli rails
的说明不包括尾随斜杠

如果我加上尾随斜杠,我得到:

Uncaught Error: Assertion Failed: Path /products does not start with the provided rootURL /products/
我意识到我在这里的第一个余烬应用程序中可能缺少一些非常基本的东西。非常真诚地感谢您提供的任何帮助。

我找到了答案

因此,继续并将尾部斜杠添加到
baseURL
。然后按照上面链接的帖子中的说明进行操作,我将在这里进行总结:

class YourEmberAppController

  before_action :ensure_trailing_slash

  respond_to :html, :js

  def index
    render :index
  end

  def vehicles
  end

  def save
  end

  private

  def ensure_trailing_slash
    unless trailing_slash?
      redirect_to url_for(params.merge(trailing_slash: true)), status: 301
    end
  end

  def trailing_slash?
    request.env['REQUEST_URI'].match(/[^\?]+/).to_s.last == '/'
  end

end

这样做,您的页面将显示“欢迎来到Ember”。

在Rails的
路线中。rb

get 'products', to: redirect('/products/'), constraints: lambda { |req| req.env['REQUEST_URI'].last != '/' }

我还了解到,这是一种在Rails应用程序中包含Ember应用程序的老式方法。
get 'products', to: redirect('/products/'), constraints: lambda { |req| req.env['REQUEST_URI'].last != '/' }