垃圾路径和路径 [英] Ember Routes and Rails Routes

查看:139
本文介绍了垃圾路径和路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是自从我开始学习Ember以了解如何使用Rails以来的问题。



Rails具有一个具有任意数量的现有路由的routes.rb文件。
Ember有自己独立的一组路线。



当路由不存在于rails中时,浏览器如何知道寻找Ember路由? p>

rails似乎需要将浏览器重定向到Ember似乎是合乎逻辑的,但我没有看到任何地方写入。



在大多数情况下,如果有一个现有的rails应用程序,则route.rb中的路由起到将资源转换为api的作用,并使数据通过url获取。



那部分很简单。我可以看到使用该url.json的数据



我现在正在尝试让浏览器识别一条路线(轨道中存在的一条路线) Ember路由。



与显示数据无关。我只想看到模板渲染。



我感觉到路由只是被浏览器神奇地识别(没有提到Ember路由在route.rb)基于Ember框架中幕后发生的事情,但这不是我在现实中遇到的情况。



我继续收到路由错误: / p>

在2013-08-08 12:44:30 -0700
启动GET/ newslinks127.0.0.1 ActionController :: RoutingError(没有路线匹配[GET]/ newslinks):



这是我的application.js

  // = require jquery 
// = require jquery-ui
// = require jquery_ujs
// = require jquery -fileupload / basic
// = require jquery-fileupload / vendor / tmpl
// = require selected-jquery
// = require bootstrap
// = require bootstrap-notify
// = require jquery.limit-1.2.source
// = require bootstrap-switch
// = require handlebars
// = require ember
/ / = require ember-data
// = require_self
// = require app

这是我的app.js:

  App = Ember.Application.create({
LOG_TRANSITIONS:true,
ready:function(){
console.log('App ready');
}
});

App.Router.map(function(){
this.resource('newslinks',{path:'/'});
});

App.IndexRoute = Ember.Route.extend({
redirect:function(){
this.transitionTo('newslinks');
}
});

App.NewslinksRoute = Ember.Route.extend({
model:function(){
return App.Newslink.find();
}
});

DS.RESTAdapter.reopen({
namespace:'api / v1'
});

App.Store = DS.Store.extend({
revision:13
});

App.Newslink = DS.Model.extend({
name:DS.attr('string')
});

我被告知这应该是正常工作,但不是。不知道在哪里可以寻求帮助,所以如果你有任何建议或有一点时间,想要自由的问题,请让我知道。



修改



添加routes.rb作为参考:

 code>命名空间:api do 
命名空间:v1 do
资源:newslinks
end
end


解决方案


当路由不存在于rails中时,浏览器如何知道寻找Ember路由?


没有。当您在浏览器中输入URL时,会向服务器发出请求,然后rails应该响应一些内容。因此,在这种情况下,当您要求/ newslinks网址时,您希望rails使用包含您的ember应用程序的HTML页面进行响应。



加载该页面时, ember应用程序将启动,从那里将使用ember-router来处理您的ember应用程序上下文中的链接。



有意义吗?


This is the question that I've had ever since I started studying Ember to see how it might work with Rails.

Rails has a routes.rb file with any number of existing routes. Ember has its own separate set of routes.

How does the browser know to look for an Ember route when the route does not exist in rails?

It would seem logical that rails would need to redirect the browser to Ember, but I have not seen that written up anywhere.

In most cases where there's an existing rails app, the route in routes.rb plays the role of turning the resource into an api and that makes the data available through a url.

That part was easy. I can see the data using that url.json

I am now at the stage of trying to get the browser to recognize one single route (of many existing in rails) through Ember routing.

This does not have anything to do with showing the data. I just want to see the template render.

I get the feeling that the route is just magically recognized by the browser (without any mention of Ember routing in routes.rb) based on what's happening behind the scenes in the Ember framework, but that's not what I've experienced in reality.

I keep getting a routing error:

Started GET "/newslinks" for 127.0.0.1 at 2013-08-08 12:44:30 -0700 ActionController::RoutingError (No route matches [GET] "/newslinks"):

Here is my application.js

//= require jquery
//= require jquery-ui
//= require jquery_ujs
//= require jquery-fileupload/basic
//= require jquery-fileupload/vendor/tmpl
//= require chosen-jquery
//= require bootstrap
//= require bootstrap-notify
//= require jquery.limit-1.2.source
//= require bootstrap-switch
//= require handlebars
//= require ember
//= require ember-data
//= require_self
//= require app

Here is my app.js:

App = Ember.Application.create({
  LOG_TRANSITIONS: true,
  ready: function() {
    console.log('App ready');
  }
});

App.Router.map(function() {
    this.resource('newslinks', { path: '/' });
});

App.IndexRoute = Ember.Route.extend({
  redirect: function() {
    this.transitionTo('newslinks');
  }
});

App.NewslinksRoute = Ember.Route.extend({
  model: function() {
  return App.Newslink.find();
  }
});

DS.RESTAdapter.reopen({
  namespace: 'api/v1'
});

App.Store = DS.Store.extend({
  revision: 13
});

App.Newslink = DS.Model.extend({
  name: DS.attr('string')
});

I've been told that this should actually be working, but it's not. Not sure where else to turn for help at this point, so if you have any recommendations or have a little time and want to freelance on the issue, please let me know.

Edit

Adding routes.rb for reference:

namespace :api do
    namespace :v1 do
      resources :newslinks
    end
  end

解决方案

How does the browser know to look for an Ember route when the route does not exist in rails?

It doesn't. When you enter a url in browser, it will make request to the server, then rails should respond with some content. So in this case when the "/newslinks" url is requested you want rails to respond with an HTML page that includes your ember application.

When that page is loaded, the ember app will boot up and from there the ember-router will be used to handle links within the context of your ember app.

Make sense?

这篇关于垃圾路径和路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆