Ruby on rails 设计不更新任何东西,但密码
使用Ruby on rails 设计不更新任何东西,但密码,ruby-on-rails,ruby-on-rails-4,devise,Ruby On Rails,Ruby On Rails 4,Devise,使用designe 3.2.4和Rails 4.1.1,我在designe更新除电子邮件和密码之外的任何与用户相关的内容时遇到问题 我的edit.html.erb中包含以下内容(除了默认设置): 然而,当我提交表单时,我得到了正确的参数(包括更改的计划id): 但是,除了新密码之外,实际数据库中没有任何更改。有人有什么想法吗 以下是put的整个服务器日志: Started PUT "/users" for 127.0.0.1 at 2014-06-11 11:30:09 -0400 Proces
designe 3.2.4
和Rails 4.1.1
,我在designe
更新除电子邮件
和密码
之外的任何与用户相关的内容时遇到问题
我的edit.html.erb
中包含以下内容(除了默认设置):
然而,当我提交表单时,我得到了正确的参数(包括更改的计划id
):
但是,除了新密码之外,实际数据库中没有任何更改。有人有什么想法吗
以下是put的整个服务器日志:
Started PUT "/users" for 127.0.0.1 at 2014-06-11 11:30:09 -0400
Processing by Users::RegistrationsController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"Token", "user"=>
{"email"=>"taylor@taylorskidmore.com", "password"=>"[FILTERED]", "password_confirmation"=>
"[FILTERED]", "current_password"=>"[FILTERED]", "plan_id"=>"1"}, "commit"=>"Update"}
User Load (0.3ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 2 ORDER BY `users`.`id` ASC LIMIT 1
User Load (0.2ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 2 LIMIT 1
(0.1ms) BEGIN
Division Load (0.2ms) SELECT `divisions`.* FROM `divisions` WHERE `divisions`.`name` = 'Sample Name' LIMIT 1
Plan Load (0.2ms) SELECT `plans`.* FROM `plans` WHERE `plans`.`company` = 'company 1' AND `plans`.`shortname` = 'plan 1' LIMIT 1
(0.1ms) COMMIT
Redirected to http://localhost:3000/
Completed 302 Found in 106ms (ActiveRecord: 2.6ms)
我的user.rb
:
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable, :confirmable,
:recoverable, :rememberable, :trackable, :validatable
validate :user_is_eligible
belongs_to :plan
belongs_to :division
def is_eligible?
db = Sequel.connect('mysql2://localhost')
eligible_users = db[:eligible_users]
user = eligible_users.where(:first_name => self.first_name, :last_name => self.last_name,
:employee_number => self.employee_number)[:id]
if user.present?
@division = Division.find_by_name(user[:division])
self.division_id = @division.id
self.plan_id = Plan.find_by_company_and_shortname(@division.company, user[:plan].downcase).id
end
user.present?
end
private
def user_is_eligible
errors.add(:base, "Check Employee Information and Try Again") unless self.is_eligible?
end
end
class用户self.first\u name,:last\u name=>self.last\u name,
:employee_number=>self.employee_number)[:id]
如果user.present?
@division=division.按名称查找(用户[:division])
self.division\u id=@division.id
self.plan\u id=plan.find\u by\u company\u和\u shortname(@division.company,user[:plan].downcase).id
结束
用户:现在吗?
结束
私有的
def用户_符合条件
错误。添加(:base,“检查员工信息并重试”),除非self.u符合条件?
结束
结束
您在用户
模型中有一个验证,您正在重置计划id
,这就是您从表单传递的计划id
在数据库中没有得到更新的原因
根据聊天讨论,您只需要在创建用户记录时进行验证,因此您所能做的就是为验证传递一个选项on::create
,如下所示,以便在更新现有用户记录时不会执行验证
class User < ActiveRecord::Base
#..
validate :user_is_eligible, on: :create ## Updated this line
## ...
end
class用户
您是否在应用程序控制器
中的过滤器之前添加了作为过滤器之前:配置允许的参数,如果::设计控制器?
?@KirtiThorat在操作之前
,但是是的。您可以共享应用程序控制器
的完整代码吗。在问题中更新它。@KirtiThorat已更新!如果您可以共享在编辑表单提交时生成的完整服务器日志,那也太好了。
Started PUT "/users" for 127.0.0.1 at 2014-06-11 11:30:09 -0400
Processing by Users::RegistrationsController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"Token", "user"=>
{"email"=>"taylor@taylorskidmore.com", "password"=>"[FILTERED]", "password_confirmation"=>
"[FILTERED]", "current_password"=>"[FILTERED]", "plan_id"=>"1"}, "commit"=>"Update"}
User Load (0.3ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 2 ORDER BY `users`.`id` ASC LIMIT 1
User Load (0.2ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 2 LIMIT 1
(0.1ms) BEGIN
Division Load (0.2ms) SELECT `divisions`.* FROM `divisions` WHERE `divisions`.`name` = 'Sample Name' LIMIT 1
Plan Load (0.2ms) SELECT `plans`.* FROM `plans` WHERE `plans`.`company` = 'company 1' AND `plans`.`shortname` = 'plan 1' LIMIT 1
(0.1ms) COMMIT
Redirected to http://localhost:3000/
Completed 302 Found in 106ms (ActiveRecord: 2.6ms)
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable, :confirmable,
:recoverable, :rememberable, :trackable, :validatable
validate :user_is_eligible
belongs_to :plan
belongs_to :division
def is_eligible?
db = Sequel.connect('mysql2://localhost')
eligible_users = db[:eligible_users]
user = eligible_users.where(:first_name => self.first_name, :last_name => self.last_name,
:employee_number => self.employee_number)[:id]
if user.present?
@division = Division.find_by_name(user[:division])
self.division_id = @division.id
self.plan_id = Plan.find_by_company_and_shortname(@division.company, user[:plan].downcase).id
end
user.present?
end
private
def user_is_eligible
errors.add(:base, "Check Employee Information and Try Again") unless self.is_eligible?
end
end
class User < ActiveRecord::Base
#..
validate :user_is_eligible, on: :create ## Updated this line
## ...
end