用于保存用户的自定义变量,但未出现在控制台中

丽兹

我使用Devise设置了一个常规用户模块,但是随后我想向其中添加更多变量,并且遇到了麻烦。我按照本教程进行了以下更改:

我的routesdevise现在显示为:

devise_for :users, :controllers => { registrations: 'registrations' }

我的registrations_controller是:

class RegistrationsController < Devise::RegistrationsController
  private

  def sign_up_params
    params.require(:user).permit(:first_name, :last_name, :role, :gender, :dob, :age, :goal_weight, :goal_muscle, :goal_bodyimage, :goal_performance, :goal_endurance, :goal_health, :email, :password, :password_confirmation)
  end

  def account_update_params
    params.require(:user).permit(:first_name, :last_name, :role, :gender, :dob, :age, :goal_weight, :goal_muscle, :goal_bodyimage, :goal_performance, :goal_endurance, :goal_health, :email, :password, :password_confirmation, :current_password)
  end
end

我添加的字段我newedit在其他风格的看法。

这是我的new表格:

<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
  <%= devise_error_messages! %>

  <div class="field text-left">
    <%= f.label :first_name %><br />
    <%= f.text_field :first_name, autofocus: true, class: "form-control" %>
  </div>

  <div class="field text-left">
    <%= f.label :last_name %><br />
    <%= f.text_field :last_name, class: "form-control" %>
  </div>

  <div class="field text-left">
    <%= f.label :gender %><br />
    <%= f.select :gender, options_for_select([['Prefer Not to Say', 'Prefer Not to Say'],['Female', 'Female'],['Male', 'Male']]), {}, {class: "form-control"} %>
  </div>

  <div class="field text-left">
    <%= f.label :dob %><br />
    <%= f.date_field :dob, class: "form-control" %>
  </div>

  <div class="field text-left">
    <%= f.label "What are your goals?" %><br />
    <p><%= f.check_box :goal_weight, value: "1", checked: false, options: {} %> Lose Weight<br>
    <%= f.check_box :goal_muscle, value: "1", checked: false, options: {} %> Gain Muscle<br>
    <%= f.check_box :goal_bodyimage, value: "1", checked: false, options: {} %> Better Overall Body Composition<br>
    <%= f.check_box :goal_performance, value: "1", checked: false, options: {} %> Increase Sports Performance<br>
    <%= f.check_box :goal_endurance, value: "1", checked: false, options: {} %> Gain Endurance<br>
    <%= f.check_box :goal_health, value: "1", checked: false, options: {} %> Better Health</p>
  </div>

  <div class="field text-left">
    <%= f.label :email %><br />
    <%= f.email_field :email, class: "form-control" %>
  </div>

  <div class="field text-left">
    <%= f.label :password %>
    <% if @minimum_password_length %>
    <em>(<%= @minimum_password_length %> characters minimum)</em>
    <% end %><br />
    <%= f.password_field :password, autocomplete: "off", class: "form-control" %>
  </div>

  <div class="field text-left">
    <%= f.label :password_confirmation %><br />
    <%= f.password_field :password_confirmation, autocomplete: "off", class: "form-control" %>
  </div>

  <div class="actions">
    <%= f.submit "Sign up", class: "btn btn-primary" %>
  </div>
<% end %>

这是我的edit表格:

<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>
  <%= devise_error_messages! %>

  <div class="field">
    <%= f.label :first_name %><br />
    <%= f.text_field :first_name, autofocus: true, class: "form-control" %>
  </div>

  <div class="field">
    <%= f.label :last_name %><br />
    <%= f.text_field :last_name, class: "form-control" %>
  </div>

  <div class="field">
    <%= f.label :gender %><br />
    <%= f.select :gender, options_for_select([['Prefer Not to Say', 'Prefer Not to Say'],['Female', 'Female'],['Male', 'Male']]), {}, {class: "form-control"} %>
  </div>

  <div class="field">
    <%= f.label :dob %><br />
    <%= f.date_field :dob, class: "form-control" %>
  </div>

  <div class="field">
    <%= f.label "What are your goals?" %><br />
    <p><%= f.check_box :goal_weight, value: "1", checked: false, options: {} %> Lose Weight<br>
    <%= f.check_box :goal_muscle, value: "1", checked: false, options: {} %> Gain Muscle<br>
    <%= f.check_box :goal_bodyimage, value: "1", checked: false, options: {} %> Better Overall Body Composition<br>
    <%= f.check_box :goal_performance, value: "1", checked: false, options: {} %> Increase Sports Performance<br>
    <%= f.check_box :goal_endurance, value: "1", checked: false, options: {} %> Gain Endurance<br>
    <%= f.check_box :goal_health, value: "1", checked: false, options: {} %> Better Health</p>
  </div>

  <div class="field">
    <%= f.label :email %><br />
    <%= f.email_field :email, class: "form-control", autofocus: true %>
  </div>

  <% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
    <div>Currently waiting confirmation for: <%= resource.unconfirmed_email %></div>
  <% end %>

  <div class="field">
    <%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
    <%= f.password_field :password, class: "form-control", autocomplete: "off" %>
  </div>

  <div class="field">
    <%= f.label :password_confirmation %><br />
    <%= f.password_field :password_confirmation, class: "form-control", autocomplete: "off" %>
  </div>

  <div class="field">
    <%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
    <%= f.password_field :current_password, class: "form-control", autocomplete: "off" %>
  </div>

  <div class="actions">
    <%= f.submit "Update My Info", class: "btn btn-primary" %>
  </div>
<% end %>

所有表单均正确呈现。当我点击submitupdate看到闪光灯时,通知您信息已成功保存。

当我保存信息时,我在服务器中得到了类似的信息,表明正在保存包括复选框值在内的新信息:

Started PUT "/users" for ::1 at 2016-06-03 17:17:42 -0700
Processing by RegistrationsController#update as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"DomUJ8aFghDIOPYsWQPlB7KnmFt27ZDcPOf7SdG4PWvI8QgI3OZP5mscbVfpGtlNpIZKTIqhL+RRwj1/3VT9AQ==", "user"=>{"first_name"=>"Test", "last_name"=>"Testerson", "gender"=>"Prefer Not to Say", "dob"=>"2008-08-08", "goal_weight"=>"0", "goal_muscle"=>"1", "goal_bodyimage"=>"0", "goal_performance"=>"1", "goal_endurance"=>"0", "goal_health"=>"0", "email"=>"[email protected]", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "current_password"=>"[FILTERED]"}, "commit"=>"Update My Info"}
  User Load (0.1ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = ?  ORDER BY "users"."id" ASC LIMIT 1  [["id", 2]]
  User Load (0.1ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1  [["id", 2]]
   (0.1ms)  begin transaction
  SQL (0.4ms)  UPDATE "users" SET "goal_weight" = ?, "goal_performance" = ?, "updated_at" = ? WHERE "users"."id" = ?  [["goal_weight", 0], ["goal_performance", 1], ["updated_at", "2016-06-04 00:17:43.005855"], ["id", 2]]
   (0.6ms)  commit transaction
Redirected to http://localhost:3000/
Completed 302 Found in 148ms (ActiveRecord: 1.2ms)

这是麻烦开始的地方。之后,当我返回edit页面时,所有新变量均显示在其字段中,但复选框除外(无论之前已检查了多少个/很少:

保存新变量后,样本编辑表单

然后,当我在控制台中检查用户时,将不显示任何新变量:

irb(main):007:0> User.second
  User Load (7.5ms)  SELECT  "users".* FROM "users"  ORDER BY "users"."id" ASC LIMIT 1 OFFSET 1
=> #<User id: 2, email: "[email protected]", encrypted_password: "$2a$11$y9/F8GQ9sTUK7Hm.b81Eo.VEbvvZ93XdOdZivAgQxhB...", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 1, current_sign_in_at: "2016-06-04 00:04:34", last_sign_in_at: "2016-06-04 00:04:34", current_sign_in_ip: "::1", last_sign_in_ip: "::1", created_at: "2016-06-04 00:04:34", updated_at: "2016-06-04 00:17:43">

在另一方面,我CAN使用ERB喜欢叫他们起来等地<%= @user.first_name %>

谁能帮我解决这个问题,以便保存所有新变量?

附加信息:

这是将新变量添加到user模型的迁移

class FlushOutUser < ActiveRecord::Migration
  def change
    add_column :users, :full_name, :string
    add_column :users, :first_name, :string
    add_column :users, :last_name, :string
    add_column :users, :role, :string
    add_column :users, :gender, :string
    add_column :users, :dob, :date
    add_column :users, :age, :integer
    add_column :users, :goal_weight, :integer
    add_column :users, :goal_muscle, :integer
    add_column :users, :goal_bodyimage, :integer
    add_column :users, :goal_performance, :integer
    add_column :users, :goal_endurance, :integer
    add_column :users, :goal_health, :integer
  end
end
阿南德

从所有复选框中删除选中:false。这应该可以解决复选框问题。例如:

<%= f.check_box :goal_weight, value: "1", options: {} %> Lose Weight<br>

更新:users表确实具有自定义字段列-正如您在注释中提到的(但未在问题控制台输出中提及),...在控制台输出中,用户末尾带有省略号()。这意味着还有更多字段。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

WPF自定义用户界面未出现在

来自分类Dev

部分表单正在控制台中呈现,但未出现在浏览器中

来自分类Dev

自定义指令未出现在页面中

来自分类Dev

Liferay 6.1 ga2 CE:自定义portlet部署成功,但未出现在门户中

来自分类Dev

由kops创建的EKS集群未出现在AWS控制台中

来自分类Dev

在控制台中获取未出现在CMD中的错误

来自分类Dev

Parse对象的新列未出现在Parse应用程序核心控制台中

来自分类Dev

Ansible 实例未出现在 AWS 控制台上

来自分类Dev

+符号出现在R中的控制台中

来自分类Dev

自定义帖子类型未出现在Wordpress管理菜单中

来自分类Dev

UILabels未出现在自定义UITableViewCell类中

来自分类Dev

复选框未出现在自定义ListView中

来自分类Dev

自定义窗口小部件(开关)未出现在ActionBar中

来自分类Dev

自定义帖子类型未出现在nav_menu中

来自分类Dev

log4net.Ext.Json自定义属性未出现在json中

来自分类Dev

自定义类未出现在情节提要中

来自分类Dev

角度自定义css类未出现在视图中

来自分类Dev

自定义Xib单元格未出现在UITableView swift中

来自分类Dev

UILabels未出现在自定义UITableViewCell类中

来自分类Dev

iOS自定义UIButton未出现在视图中

来自分类Dev

从更新函数调用时,自定义 SKShapeNode 未出现在场景中

来自分类Dev

VSO 中的 MultipleLines 自定义字段未出现在 Power BI 报表的数据集中

来自分类Dev

自定义小部件未出现在主窗口中

来自分类Dev

数据框仅出现在控制台中,而不出现在环境中(Rstudio)

来自分类Dev

用户定义的函数结果未出现在Excel中

来自分类Dev

AWS Cognito:可以通过CognitoUserPool找到用户,但不会出现在AWS管理控制台中

来自分类Dev

Ant任务:在ant build中,我正在使用Java任务,在这里我使用了未出现在eclipse控制台中的system.out.println

来自分类Dev

Laravel 4自定义软件包未出现在autoload_namespace.php中

来自分类Dev

Tomcat输出未出现在控制台视图中

Related 相关文章

  1. 1

    WPF自定义用户界面未出现在

  2. 2

    部分表单正在控制台中呈现,但未出现在浏览器中

  3. 3

    自定义指令未出现在页面中

  4. 4

    Liferay 6.1 ga2 CE:自定义portlet部署成功,但未出现在门户中

  5. 5

    由kops创建的EKS集群未出现在AWS控制台中

  6. 6

    在控制台中获取未出现在CMD中的错误

  7. 7

    Parse对象的新列未出现在Parse应用程序核心控制台中

  8. 8

    Ansible 实例未出现在 AWS 控制台上

  9. 9

    +符号出现在R中的控制台中

  10. 10

    自定义帖子类型未出现在Wordpress管理菜单中

  11. 11

    UILabels未出现在自定义UITableViewCell类中

  12. 12

    复选框未出现在自定义ListView中

  13. 13

    自定义窗口小部件(开关)未出现在ActionBar中

  14. 14

    自定义帖子类型未出现在nav_menu中

  15. 15

    log4net.Ext.Json自定义属性未出现在json中

  16. 16

    自定义类未出现在情节提要中

  17. 17

    角度自定义css类未出现在视图中

  18. 18

    自定义Xib单元格未出现在UITableView swift中

  19. 19

    UILabels未出现在自定义UITableViewCell类中

  20. 20

    iOS自定义UIButton未出现在视图中

  21. 21

    从更新函数调用时,自定义 SKShapeNode 未出现在场景中

  22. 22

    VSO 中的 MultipleLines 自定义字段未出现在 Power BI 报表的数据集中

  23. 23

    自定义小部件未出现在主窗口中

  24. 24

    数据框仅出现在控制台中,而不出现在环境中(Rstudio)

  25. 25

    用户定义的函数结果未出现在Excel中

  26. 26

    AWS Cognito:可以通过CognitoUserPool找到用户,但不会出现在AWS管理控制台中

  27. 27

    Ant任务:在ant build中,我正在使用Java任务,在这里我使用了未出现在eclipse控制台中的system.out.println

  28. 28

    Laravel 4自定义软件包未出现在autoload_namespace.php中

  29. 29

    Tomcat输出未出现在控制台视图中

热门标签

归档