0
我有一個create
方法在我的Sessions controller
,但我仍然收到此錯誤。它也指application/create
,可能這是我的問題的根源?我在我的application controller
中也不需要create
方法嗎?會話未被創建。錯誤是'缺少模板會話/創建,應用程序/創建'
Template is missing
Missing template sessions/create, application/create with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in: * "/opt/csdashboard/app/views"
這裏是我的會話控制器:
class SessionsController < ApplicationController
def new
end
def create
dashboard_user = DashboardUsers.authenticate(params[:email], params[:password])
if dashboard_user
session[:dashboard_user_id] = dashboard_user.id
redirect_to index, :notice => 'Logged in'
else
flash.now.alert = 'Login failed'
render new
end
end
def destroy
session[:dashboard_user_id] = nil?
redirect_to root_url, :notice => 'Logged out'
end
end
這裏是我的路線:
Csdashboard::Application.routes.draw do
resources :csdashboard
resources :dashboard_users
resources :sessions
get '/log_out' => 'sessions#destroy', :as => 'log_out'
get '/log_in' => 'sessions#new', :as => 'log_in'
post '/sign_up' => 'dashboard_users#new', :as => 'sign_up'
post '/dashboard_users_index' => 'dashboard_users#new'
root :to => 'dashboard_users#new'
get 'csdashboard' => 'csdashboard#index'
get '/img/:name.:ext', :to => redirect('/assets/%{name}.%{ext}')
match '/404' => 'errors#not_found'
match '/422' => 'errors#server_error'
match '/500' => 'errors#server_error'
end
應用控制器:
class ApplicationController < ActionController::Base
protect_from_forgery
helper_method :current_user
private
def current_user
@current_user ||= DashboardUsers.find(session[:dashboard_user_id]) if session[:dashboard_user_id]
end
end
下應該有一個'會議'文件夾,裏面你應該有一個文件名爲'create.html.erb' – devanand
這樣做,它讓我過去的錯誤,非常感謝!我只是添加了一個空白的create.html.erb文件,它似乎沒問題。它應該是空白的(沒有代碼,沒有HTML)? –
有趣的問題。如果你不想展示什麼,就不需要創作。在ruby-on-rails上查找更多關於'render'的信息http://guides.rubyonrails.org/layouts_and_rendering.html – devanand