Rails:Application.html.erb突然停止渲染

时间:2016-04-07 21:59:21

标签: ruby-on-rails

我正在做一些与我的应用完全不同的事情,突然我的application.html.erb在我的视图中停止渲染。我甚至收回了我所做的所有改变,并没有解决问题。可能发生了什么?我到处搜索并尝试了不同的东西,没有任何作用。其他一切都很好。以下是包含更改的文件。

application_controller

    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
    helper_method :current_user


    def initialize(attributes = {})
       @name = attributes[:name]
       @email = attributes[:email]
    end

    def createRound
        @gamerounds = Gameround.all
        @gameround = Gameround.new({endtime: 'John Appleseed', active: true})

        respond_to do |format|
          if @gameround.save
            format.html { redirect_to @gameround, notice: 'Gameround was successfully created.' }
            format.json { render :show, status: :created, location: @gameround }
          else
            format.html { render :new }
            format.json { render json: @gameround.errors, status: :unprocessable_entity }
          end
        end
     end

    private

    def current_user
        @current_user ||= User.find(session[:user_id]) if session[:user_id]
    end

    def admin_user
        @admin_user = User.find_by(username: 'Admin')
    end

    protected 
    def authenticate_user
      if session[:user_id]
         # set current user object to @current_user object variable
        @current_user = User.find session[:user_id] 
        return true 
      else
        redirect_to(:controller => 'sessions', :action => 'login')
        return false
      end
    end
    def save_login_state
      if session[:user_id]
        redirect_to(:controller => 'sessions', :action => 'profile')
        return false
      else
        return true
      end
    end
 end

game_session控制器

  class GamesessionsController < ApplicationController
  before_action :set_gamesession, only: [:show, :edit, :update, :destroy]
  before_filter :authenticate_user, :except => [:index, :show, :new ]
  layout :application

  # GET /gamesessions
  # GET /gamesessions.json
  def index
    @gamesessions = Gamesession.all
  end

  # GET /gamesessions/1
  # GET /gamesessions/1.json
  def show
  end

  # GET /gamesessions/new
  def new
    @gamesession = Gamesession.new

    unless !session[:user_id]
      if !current_user.admin?
        redirect_to '/play'
      end
    end
  end

  # GET /gamesessions/1/edit
  def edit
  end

  # POST /gamesessions
  # POST /gamesessions.json
  def create
    Gamesession.delete_all

    @gamesession = Gamesession.new(gamesession_params)

    createRound

  end

  # PATCH/PUT /gamesessions/1
  # PATCH/PUT /gamesessions/1.json
  def update
    respond_to do |format|
      if @gamesession.update(gamesession_params)
        format.html { redirect_to @gamesession, notice: 'Gamesession was successfully updated.' }
        format.json { render :show, status: :ok, location: @gamesession }
      else
        format.html { render :edit }
        format.json { render json: @gamesession.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /gamesessions/1
  # DELETE /gamesessions/1.json
  def destroy
    @gamesession.destroy
    respond_to do |format|
      format.html { redirect_to gamesessions_url, notice: 'Gamesession was successfully destroyed.' }
      format.json { head :no_content }
    end
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_gamesession
      @gamesession = Gamesession.find(params[:id])
    end

    # Never trust parameters from the scary internet, only allow the white list through.
    def gamesession_params

      params.require(:gamesession).permit(:players, :flares, :aliens, :gamesetup, expansion:[], level:[])


    end
end

config.routes

    Rails.application.routes.draw do


  resources :gamerounds do 
    resources :currentplayers
  end 
  resources :gamesessions
  # The priority is based upon order of creation: first created -> highest priority.
  # See how all your routes lay out with "rake routes".

 # Artikkel, Alien liste
  resources :expansions do
    resources :aliens
  end

  resources :users



  # You can have the root of your site routed with "root"
  root 'gamesessions#new'
  get "signup", :to => "users#new"
  get "login", :to => "sessions#login"
  post "login_attempt", :to => "sessions#login_attempt"
  get "logout", :to => "sessions#logout"
  get "profile", :to => "sessions#profile"
  get "setting", :to => "sessions#setting"
  get "play", :to => "gamesessions#index"

  get "aliens", :to => "aliens#index"


  #match ':controller(/:action(/:id))(.:format)'

  # Example of regular route:
  #   get 'products/:id' => 'catalog#view'

  # Example of named route that can be invoked with purchase_url(id: product.id)
  #   get 'products/:id/purchase' => 'catalog#purchase', as: :purchase

  # Example resource route (maps HTTP verbs to controller actions automatically):
  #   resources :products

  # Example resource route with options:
  #   resources :products do
  #     member do
  #       get 'short'
  #       post 'toggle'
  #     end
  #
  #     collection do
  #       get 'sold'
  #     end
  #   end

  # Example resource route with sub-resources:
  #   resources :products do
  #     resources :comments, :sales
  #     resource :seller
  #   end

  # Example resource route with more complex sub-resources:
  #   resources :products do
  #     resources :comments
  #     resources :sales do
  #       get 'recent', on: :collection
  #     end
  #   end

  # Example resource route with concerns:
  #   concern :toggleable do
  #     post 'toggle'
  #   end
  #   resources :posts, concerns: :toggleable
  #   resources :photos, concerns: :toggleable

  # Example resource route within a namespace:
  #   namespace :admin do
  #     # Directs /admin/products/* to Admin::ProductsController
  #     # (app/controllers/admin/products_controller.rb)
  #     resources :products
  #   end
end

1 个答案:

答案 0 :(得分:3)

您正在控制器中定义initialize方法而不调用super

def initialize(attributes = {})
   @name = attributes[:name]
   @email = attributes[:email]
   super
end