当我从下面的 job.rb 模型中删除 Devise 模块时,jobs_controller.rb 出现问题:
class Job < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :contact_email, :contact_phone, :description, :district, :due_date, :expiration_date, :job_title, :posting_date, :requirements, :salary, :submission_process
end
然后我删除了 Devise 模块,并得到了结果模型:
class Job < ActiveRecord::Base
# Setup accessible (or protected) attributes for your model
attr_accessible :contact_email, :contact_phone, :description, :district, :due_date, :expiration_date, :job_title, :posting_date, :requirements, :salary, :submission_process
end
进行此转换时引发的错误显示在以下跟踪中:
ActiveRecord::StatementInvalid in JobsController#create
SQLite3::ConstraintException: constraint failed: INSERT INTO "jobs" ("contact_email", "contact_phone", "created_at", "current_sign_in_at", "current_sign_in_ip", "description", "district", "due_date", "email", "encrypted_password", "expiration_date", "job_title", "last_sign_in_at", "last_sign_in_ip", "posting_date", "remember_created_at", "requirements", "reset_password_sent_at", "reset_password_token", "salary", "sign_in_count", "submission_process", "updated_at") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
app/controllers/jobs_controller.rb:49:in `block in create'
app/controllers/jobs_controller.rb:48:in `create'
我有一个用户模型和一个工作模型,该应用程序由一个基本的脚手架组成,允许用户发布和查看工作,这取决于使用 Devise 的正确身份验证。我对适当的后端构造相对较新,并且在前端视图类型 Rails 方面有更多经验。我不确定我是否需要在 Job 模型中或仅在 User 模型中存在 Devise。