0

TODOリストの申請を行いました。

デバイスをインストールし、2 種類のユーザーを定義したいと考えています。

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'
4

1 に答える 1