0

嗨,我目前正在使用设计 gem 和一些 /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>

Not LOADED 在页面 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

应用控制器:

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
4

1 回答 1

0

刚刚在 home_controller 中添加了一个方法,用于 Rails 遍历查找内容的索引页面,在加载 index.html.erb 时,token 方法也需要更新:

def index
    render layout: 'application'
end

def token
  render layout: 'application'
end
于 2013-08-22T07:55:01.817 回答