1

나는 레일에 엠버를 사용하여 응용 프로그램의 기본 사항을 설정하기 위해 노력하고있어, 나는이 오류 받고 있어요 : 경로를 처리하는 동안오류가 발생했습니다. - 왜 데이터 양식 레일을 검색하지 않습니까?

오류 : 게시물

엠버가에 대해 뭔가를 말했다 경우 도움이 될 것입니다 오류,하지만 그것을하지 않았습니다. 문제의 코드는 다음과 같습니다 (필요한 부분을 모두 포함하고 있다고 생각합니다).

// PostsRoute 

App.PostsRoute = Ember.Route.extend({ 
    model: function(){ 
     return this.store.find('post'); 
     // return [{title: 'fixture'}, {title: '2'}] 
    } 

}) 

// Router. 

App.Router.map(function() { 
    // location: 'auto', 
    // rootURL: '/', 
    this.resource('posts', { path: '/' }) 

}); 

// Routes.rb 
    resources :posts do 
    resources :comments 
    end 

// Post model - Ember 
App.Post = DS.Model.extend({ 
    title: DS.attr('string'), 
    description: DS.attr('string'), 

    imageFileName: DS.attr('string'), 
    imageContentType: DS.attr('string'), 
    imageFileSize: DS.attr('number'), 
    imageUpdatedAt: DS.attr('date'), 

    createdAt: DS.attr('date'), 
    updatedAt: DS.attr('date'), 

    userId: DS.attr('number'), 
}); 


// Posts controller.rb 

class PostsController < ApplicationController 
    before_action :set_post, only: [:show, :edit, :update, :destroy] 

    respond_to :html 

    def index 
    @posts = Post.all 
    puts "in PostsController index. " 
    puts @posts 
    respond_with(@posts) 
    end 

    ... 

// Post Serializer 
class PostSerializer < ActiveModel::Serializer 
    attributes :id, :title, :description, :created_at, :updated_at, :user_id, :image_file_name, :image_content_type, :image_file_size, :image_updated_at 
end 

Ember가 Rails API에서 데이터를 수신하려면 무엇을 설정해야하는지 이해하려고합니다. 레일스 - 현명한, 그것은 데이터를 반환 괜찮아요. 내가 이해에서

, 여기에 응용 프로그램이가는 방법이다. Ember는 먼저 경로 (여기서는 PostsRoute)를 확인합니다. 경로는 '모델'을 가질 것으로 예상되므로 Model 속성을 살펴 봅니다. 여기에서 model 속성은 Store에 전화를 걸어 모든 게시물을 가져옵니다. 즉 this.store.find ('post'). [고정 배열이 호출 장착 잘 작동하는 것 같다.]

이것은 레일가 PostsController 지수 함수를 호출한다. 나는이 기능에 도달했는지 확인할 수있다. index 함수는 activerecord post 모델과 함께 변수를 반환합니다. 엠버 그것을 사용할 수 있도록하기위한

은 여기에서 게시물은 JSON-는 ified해야합니다. 그래서 그들은 serializer, 여기 post_serializer.rb를 통과하게됩니다. JSON 양식으로 보낼 특성을 결정합니다.

게시물이 실제로 PostsController.rb의 인덱스 함수에서 가져온 것으로 확인 되었기 때문에이 직렬화 부분을 처리하는 방식에 문제가 있다고 의심하지만 (저는 믿습니다) Ember 로의 여행.

내가 이해할 수없는 것은 그 이유입니다. 내가 놓친 게 뭐지? 그것은 어떤 문제가있는 경우

는, 내가 처음이 프로젝트를 알고 싶었 기 때문에 나는 아직 포함되지 않은 일부 has_many 관계가있다.

Error while processing route: posts ember.js?body=1:15376 
logToConsole ember.js?body=1:15376 
logError ember.js?body=1:26315 
defaultActionHandlers.error ember.js?body=1:26272 
triggerEvent ember.js?body=1:26363 
trigger ember.js?body=1:46876 
Transition.trigger ember.js?body=1:46721 
(anonymous function) ember.js?body=1:46526 
tryCatch ember.js?body=1:47310 
invokeCallback ember.js?body=1:47322 
publish ember.js?body=1:47293 
publishRejection ember.js?body=1:47235 
(anonymous function) ember.js?body=1:29438 
DeferredActionQueues.invoke ember.js?body=1:682 
DeferredActionQueues.flush ember.js?body=1:752 
Backburner.end ember.js?body=1:138 
Backburner.run ember.js?body=1:193 
run ember.js?body=1:18226 
hash.error ember-data.js?body=1:1886 
fire jquery.js?body=1:3120 
self.fireWith jquery.js?body=1:3232 
done jquery.js?body=1:9278 
callback jquery.js?body=1:9686 

답변

1

당신의 model 후크에 의해 반환 약속은 거부한다 : 그리고 완전성을 위해, 여기에 크롬의 콘솔에 따라, 전체 오류입니다. 브라우저의 경로를로드 할 때 debugger 호출이 실행을 일시 중지

App.PostsRoute = Ember.Route.extend({ 
    model: function() { 
    return this.store.find('post').catch(function (error) { 
     debugger; 
    }); 
    } 
}); 

, 당신은 오류가보고되고 볼 수 있습니다 : 발견에 왜이 함께 모델 후크의 코드를 교체합니다. 이상적으로, 오류에는 사물이 작동하지 않는 이유에 대한 질문에 대한 대답이 포함됩니다.