0
我做了TODO清單的申請。與設計的待辦事項清單
我安裝裝置和後要定義兩種用戶:
1) admin
2) worker
,所以我將創建管理控制器。同時,我創建了user_controller。
我要強制註冊,爲了讓工人更新他的任務(完成與否),所以我嘗試:
class WorkersController < ApplicationController
before_filter :authenticate_user!
PS,我的模型的名字是user.rb:
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :lockable, :timeoutable, :confirmable and :activatable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation
# attr_accessible :title, :body
end
但是:authenticate_user!不工作。即使我退出,我也可以創建一項任務。
之後,我必須知道登錄的用戶的郵件是什麼(爲了更新他的任務)。所以我要寫類似:
def index
@email = params[:session][:email]
,但我得到了一個錯誤:
所有的NoMethodError in WorkersController#index
undefined method `[]' for nil:NilClass
Rails.root: /home/alon/projects/TODOLIST
Application Trace | Framework Trace | Full Trace
app/controllers/workers_controller.rb:8:in `index'