Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails 4.0+;为用户模型设计3.0.0自定义属性_Ruby On Rails_Devise - Fatal编程技术网

Ruby on rails Rails 4.0+;为用户模型设计3.0.0自定义属性

Ruby on rails Rails 4.0+;为用户模型设计3.0.0自定义属性,ruby-on-rails,devise,Ruby On Rails,Devise,我正在使用Rails 4和Desive 3.0.0,我对使用这些新的强大参数还不熟悉。我使用迁移将名字和姓氏添加到用户模型中,然后基于Desive Wiki将以下内容添加到我的应用程序\u controller.rb中 class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use

我正在使用Rails 4和Desive 3.0.0,我对使用这些新的强大参数还不熟悉。我使用迁移将名字和姓氏添加到用户模型中,然后基于Desive Wiki将以下内容添加到我的应用程序\u controller.rb中

class ApplicationController < ActionController::Base
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  before_filter :configure_permitted_parameters, if: :devise_controller?
  protect_from_forgery with: :exception
  protected
  def configure_permitted_parameters
    devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:first_name, :last_name, :email, :password, :password_confirmation) }
  end
end
class ApplicationController
我的注册视图(/views/design/registrations/new.html.erb)出现以下错误消息:

undefined method `first_name' for #<ActionView::Helpers::FormBuilder:0x007fdcbcbe2170>

未定义方法“first_name”,用于#少数类似问题的帖子,但没有效果。有什么想法吗?

我想你是想用
f.text\u字段

# This:
<%= f.first_name :first_name, :autofocus => true, :placeholder => 'Fist name', :class => "form-control" %>
<%= f.last_name :last_name, :placeholder => 'List name', :class => "form-control" %>

# Should become:
<%= f.text_field :first_name, :autofocus => true, :placeholder => 'Fist name', :class => "form-control" %>
     #^^^^^^^^^^
<%= f.text_field :last_name, :placeholder => 'List name', :class => "form-control" %>
     #^^^^^^^^^^
#这是:
true,:占位符=>'first name',:class=>“表单控件”%>
'列表名称',:class=>“表单控件”%>
#应成为:
true,:占位符=>'first name',:class=>“表单控件”%>
#^^^^^^^^^^
'列表名称',:class=>“表单控件”%>
#^^^^^^^^^^

我想你是想把
f.text\u字段:first\u name
f.text\u字段:last\u name
与你的常规options@MrYoshiji你是对的…老兄,谈谈不要着眼于大局而专注于小问题。发布一个答案,我会接受的。没关系,一天结束了,蒙特利尔也有一个温暖的一天。。。我明白;)一个叫蒙特勒的家伙,很高兴见到你。我欠你一杯啤酒!对不起,我以为你发完后我就接受了。我的错!
# This:
<%= f.first_name :first_name, :autofocus => true, :placeholder => 'Fist name', :class => "form-control" %>
<%= f.last_name :last_name, :placeholder => 'List name', :class => "form-control" %>

# Should become:
<%= f.text_field :first_name, :autofocus => true, :placeholder => 'Fist name', :class => "form-control" %>
     #^^^^^^^^^^
<%= f.text_field :last_name, :placeholder => 'List name', :class => "form-control" %>
     #^^^^^^^^^^