为什么我的资源没有在 Rails 4 中呈现?
Why aren't my assets rendering in Rails 4?
我一直在研究 Rails app to conglomerate directories pulled from IPFS. For some reason, app/views/layouts/application.html.erb
isn't rendering。
每个 IPFS 条目都有一个对应的 ActiveRecord 模型。 routes.rb
的相关部分是:
Rails.application.routes.draw do
resources :entries, path: :e, constraints: { id: /.*/ }
root 'entries#index'
end
EntriesController
的index
动作是:
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>
我克隆了你的代码,运行 在本地,调试并做了一些测试。
原来是控制器初始化的问题,改成这样就可以了:
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? && !@space.roots.include?(@entry)
@space.roots << @entry
end
end
if @entry.kind_of?(Blob)
send_data @entry.content, type: 'text/html', disposition: 'inline'
end
end
end
我一直在研究 Rails app to conglomerate directories pulled from IPFS. For some reason, app/views/layouts/application.html.erb
isn't rendering。
每个 IPFS 条目都有一个对应的 ActiveRecord 模型。 routes.rb
的相关部分是:
Rails.application.routes.draw do
resources :entries, path: :e, constraints: { id: /.*/ }
root 'entries#index'
end
EntriesController
的index
动作是:
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>
我克隆了你的代码,运行 在本地,调试并做了一些测试。
原来是控制器初始化的问题,改成这样就可以了:
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? && !@space.roots.include?(@entry)
@space.roots << @entry
end
end
if @entry.kind_of?(Blob)
send_data @entry.content, type: 'text/html', disposition: 'inline'
end
end
end