rails未初始化的恒定控制器参数

时间:2016-03-17 21:28:02

标签: ruby-on-rails ruby controller params

我向模型$totalmin = null; while($row = mysql_fetch_array($result)) { if (is_null($totalmin) || $row['totalmin'] < $totalmin) { $totalmin = $row['totalmin']; } echo "<tr>"; echo "<td><center>" . $totalmin . "</center></td>"; echo "</tr>"; } 添加了一个属性我已经运行了迁移并确认它在数据库中。错误发生在控制器中。

仅当我在表单中输入值时,才会抛出错误::roleid

它突出显示了创建操作中的行uninitialized constant User::Roleid

@user = User.new(user_params)定义如下:

user_params

如您所见,params.require(:user).permit(:id, :email, :encrypted_password, :fname, :lname, :roleid) 存在:

roleid

完整的错误文字是:

mysql> DESCRIBE users;
+------------------------+--------------+------+-----+---------+----------------+
| Field                  | Type         | Null | Key | Default | Extra          |
+------------------------+--------------+------+-----+---------+----------------+
| id                     | int(11)      | NO   | PRI | NULL    | auto_increment |
| email                  | varchar(255) | NO   | UNI |         |                |
| encrypted_password     | varchar(255) | NO   |     |         |                |
| reset_password_token   | varchar(255) | YES  | UNI | NULL    |                |
| reset_password_sent_at | datetime     | YES  |     | NULL    |                |
| remember_created_at    | datetime     | YES  |     | NULL    |                |
| sign_in_count          | int(11)      | NO   |     | 0       |                |
| current_sign_in_at     | datetime     | YES  |     | NULL    |                |
| last_sign_in_at        | datetime     | YES  |     | NULL    |                |
| current_sign_in_ip     | varchar(255) | YES  |     | NULL    |                |
| last_sign_in_ip        | varchar(255) | YES  |     | NULL    |                |
| created_at             | datetime     | NO   |     | NULL    |                |
| updated_at             | datetime     | NO   |     | NULL    |                |
| fname                  | varchar(255) | YES  |     | NULL    |                |
| lname                  | varchar(255) | YES  |     | NULL    |                |
| roleid                 | int(11)      | YES  |     | NULL    |                |
+------------------------+--------------+------+-----+---------+----------------+

控制器代码如下所示:

Started POST "/users" for ::1 at 2016-03-17 17:23:31 -0400
Processing by UsersController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"48xz8D0jngCGOnL7qn4A93X2qeOcmvcE8QjXah7cjsxusA7FrPK8JhmVjRNa2nflkg4qfLs5cnL2oL9cHn/iUQ==", "user"=>{"id"=>"4", "email"=>"wlrg", "encrypted_password"=>"[FILTERED]", "fname"=>"flh", "lname"=>"wflh", "roleid"=>"4"}, "commit"=>"Create User"}
Completed 500 Internal Server Error in 5ms (ActiveRecord: 0.0ms)

NameError (uninitialized constant User::Roleid):
  app/controllers/users_controller.rb:27:in `create'

0 个答案:

没有答案