您好我正在使用设计宝石和一些/layout/application.html.erb
然而,似乎这个布局只在某些页面上使用,例如我确实生成了一个脚手架并且没有加载css,我似乎无法在视图和控制器中找到任何设置。任何线索?
在显示的页面中加载:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title></title>
<meta content="authenticity_token" name="csrf-param" />
<meta content="gfE/9VmHDvDP5BbpAejL57qVZZ0c67a2G/421HvI3Ck=" name="csrf-token" />
<link href="/assets/application.css?body=1" media="all" rel="stylesheet" />
<link href="/assets/games.css?body=1" media="all" rel="stylesheet" />
<link href="/assets/stats.css?body=1" media="all" rel="stylesheet" />
<script src="/assets/jquery.js?body=1"></script>
<script src="/assets/jquery_ujs.js?body=1"></script>
<script src="/assets/turbolinks.js?body=1"></script>
<script src="/assets/bootstrap.js?body=1"></script>
<script src="/assets/games.js?body=1"></script>
<script src="/assets/stats.js?body=1"></script>
<script src="/assets/application.js?body=1"></script>
在页面中没有加载index.erb.html,正如您所看到的那样,控制器中没有方法:
<h1>Hello!</h1>
<p><a href="/admins/sign_up">Sign up as Admin</a></p>
<p><a href="/admins/sign_in">Sign in as Admin</a></p>
<p><a href="/token">Token Authentication Example</a></p>
<a href="/games">Games</a>
<p>Hello!</p>
<p>david@inkorgen.nu </p>
<p>Last sign in:2013-08-14 12:36:55 UTC </p>
未通过布局查看的控制器:
class HomeController < ApplicationController
before_action :authenticate_user!, only: :token
def token
end
def initialize
unless @game
get_games
#@levels = [] unless @levels
#get_levels
end
end
def get_levels
@levels = Level.where(:game_id=>@game)
end
# Use callbacks to share common setup or constraints between actions.
def get_games
@games = Game.where(:user_id=>:id)
end
end
的ApplicationController:
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
before_filter :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit! }
end
end
答案 0 :(得分:0)
刚刚向家庭控制器添加了一个方法,用于Rails遍历查找内容的索引页面,当加载index.html.erb时,令牌方法也需要更新:
def index
render layout: 'application'
end
def token
render layout: 'application'
end