【发布时间】:2016-06-28 21:18:19
【问题描述】:
几个小时以来我一直在尝试这个,但没有成功,所以,终于向你们寻求帮助。
场景
我有两个设计模型,即学院和经理。他们都工作正常,但我想要实现的是学院应该能够创建或删除经理。为此,我创建了一个 Codashboard 控制器#view,它只有在 College 登录后才能访问。这个控制器#view 对有一个用于提交经理电子邮件和密码并提交到数据库的表单。
问题
每当我提交表单时,我都不会收到任何错误,但更改不会提交到数据库。
详情
从终端提取
Started POST "/codashboard" for 127.0.0.1 at 2016-03-14 04:59:41 +0530
Processing by CodashboardController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"P85GD7Wnt1RYNDgxxMxrSH6tUzW/PUBvqTXs8lYHY+HkvRXnq3s/IQL50SyMeDI1xXlalztTMbTZDNcPsXuckw==", "manager"=>{"email"=>"manager11@gmail.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Sign up"}
(0.1ms) BEGIN
(0.1ms) ROLLBACK
Redirected to http://localhost:3000/codashboard
Completed 302 Found in 4ms (ActiveRecord: 0.3ms)
对应视图
<%= form_for @addmanager, url: {action: "create"} do |f| %>
<div><%= f.label :email %><br />
<%= f.email_field :email %></div>
<div><%= f.label :password %><br />
<%= f.password_field :password %></div>
<div><%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation %></div>
<div><%= f.submit "Sign up" %></div>
<% end %>
对应的控制器
class CodashboardController < ApplicationController
def index
if college_signed_in?
@managers = College.find_by_id(current_college.id).managers
@addmanager = Manager.create(params[:addmanager])
end
end
def new
@addmanager = Manager.new
end
def create
Manager.create(params[:addmanager])
redirect_to codashboard_index_path
end
def addmanager
@addmanager = Manager.new(:email => "manager8@gmail.com", :password => "qwertyuiop")
@addmanager.save
redirect_to codashboard_index_path
end
end
注意:我尝试使用默认设计表单,但它总是在创建我不想要的新用户后登录。
注意 2:方法 addmanager 工作正常,并在调用时在数据库中添加一个条目。所以,我的模型没有问题。
请提出可能的问题
【问题讨论】:
标签: ruby-on-rails database devise