Devise方法中的NoMethodError`date_of_birth'

时间:2014-07-18 17:18:09

标签: ruby-on-rails devise controller undefined registration

我正在尝试将date_of_birth添加到我的Devise表单中,但是,我一直收到一条错误消息,指出'date_of_birth'是未定义的方法。请参阅下面的代码。任何帮助将不胜感激。我整个上午一直在努力。

Devise中的NoMethodError :: Registrations#edit app / views / devise / registrations / edit.html.erb第27行引出:

错误消息 #的未定义方法`date_of_birth' 提取的来源(第27行):

   <div class="form-group">
        <%= f.label :date_of_birth %>
        <%= f.date_select :date_of_birth, class: "form-control", :autofocus => true %>
   </div>

设计/注册/修改

<div class="row">
<div class="col-md-offset-4 col-md-8">

<div class="panel panel-default">
  <div class="panel-heading">
    <div class="panel-title">
      <h1>Edit <%= resource_name.to_s.humanize %></h1>
    </div>
  </div>
  <div class="panel-body">
    <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f| %>
      <%= devise_error_messages! %>

     <div class="form-group">
        <%= f.label :avatar %>
        <%= f.file_field :avatar, class: "form-control", :autofocus => true %>
     </div> 

     <div class="form-group">
        <%= f.label :name %>
        <%= f.text_field :name, class: "form-control", :autofocus => true %>
      </div>


    <div class="form-group">
         <%= f.label :date_of_birth %>
         <%= f.date_select :date_of_birth, class: "form-control", :autofocus => true %>
    </div>


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

     <div class="form-group">
        <%= f.label :bio %>
        <%= f.text_field :bio, class: "form-control", :autofocus => true %>
      </div>

      <div class="form-group">
        <%= f.label :password %> <i>(Please leave blank if you are not updating your password.)
        <%= f.password_field :password, class: "form-control", :autocomplete => "off" %>
      </div>

      <div class="form-group">
        <%= f.label :current_password %> <i>(Current password needed to confirm your updates.)</i>
        <%= f.password_field :current_password, class: "form-control" %>
      </div>

      <div class="form-group">
        <%= f.submit "Update", class: "btn btn-danger btn-lg btn-block" %>
      </div>
    <% end %>
  </div>
  <div class="panel-footer">
    <h3>Cancel my account</h3>

    <p>Unhappy? :( <%= button_to "Cancel my account", registration_path(resource_name), :data => { :confirm => "Are you sure?" }, :method => :delete, class: "btn btn-warning" %></p>

    <%= link_to "Back", :back %>
  </div>
</div>

资产/ Application_Controller

class ApplicationController < ActionController::Base
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery with: :null_session

  before_filter :configure_permitted_parameters, if: :devise_controller?

    protected

     def configure_permitted_parameters
        devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:name, :email, :password) }
        devise_parameter_sanitizer.for(:account_update) { |u| u.permit(:name, :email, :password, :current_password, :gender, :date_of_birth, :avatar, :bio) }
   end


    def user_params
      params.require(:user).permit(:name, :email, :password, :password_confirmation)
    end


    def after_sign_in_path_for(resource)
      posts_path
    end

    def after_sign_up_path_for(resource)
      posts_path
    end

end

移植

class AddGenderToUsers < ActiveRecord::Migration
  def change
     add_column :users, :is_female, :boolean, default: false
     add_column :users, :date_of_birth, :datetime
  end
end

0 个答案:

没有答案