2017-03-17 83 views
0

我一直在Rails app to conglomerate directories pulled from IPFS上工作。由於某種原因,app/views/layouts/application.html.erbisn't rendering爲什麼我的資產不能在Rails 4中渲染?

每個IPFS條目都有一個對應的ActiveRecord模型。的routes.rb的相關部分:

Rails.application.routes.draw do 
    resources :entries, path: :e, constraints: { id: /.*/ } 
    root 'entries#index' 
end 

EntriesControllerindex動作是:

class EntriesController < ApplicationController 
    def index 
    @entries = @space.roots 
    end 
end 

application.html.erb是:

<!DOCTYPE html> 
<html> 
<head> 
    <title>Tip</title> 
    <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> 
    <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> 
    <%= csrf_meta_tags %> 
</head> 
<body> 
    <% if notice %> 
    <p class="alert alert-success"><%= notice %></p> 
    <% end %> 
    <% if alert %> 
    <p class="alert alert-danger"><%= alert %></p> 
    <% end %> 

    <%= yield %> 
</body> 
</html> 

回答

1

我克隆你的代碼,運行在本地,調試和做了一些測試。

原來,怪是在控制器的初始化,如果你把它改變這一點,它的工作原理:

class EntriesController < ApplicationController 

    # def initialize(*args) 
    # @space = Space.first_or_create() 
    # end 

    def index 
    @entries = Space.first_or_create().roots 
    end 

    def show 
    id = params[:id] 

    if id.start_with?('.../') 
     @entry = @space.lookup(id) 
    else 
     @hash = id 
     @entry = Entry.find_or_create_by(code: @hash) 

     if @entry.parents.empty? && [email protected]?(@entry) 
     @space.roots << @entry 
     end 
    end 

    if @entry.kind_of?(Blob) 
     send_data @entry.content, type: 'text/html', disposition: 'inline' 
    end 
    end 
end 
+0

我需要調用父類的構造函數。感謝您幫助我找到它。我被迷惑了。 – Will

相關問題