アプリで Geocoder を動作させようとしています。ユーザーの郵便番号を使用して場所をジオコーディングしようとしていますが、新しいサインアップを送信すると、次のエラーが発生しました。
NoMethodError in Devise::RegistrationsController#create
undefined method `latitude='
私は認証にDeviseを使用してい:zip
ます。これが関連する場合の属性のサニテーションです。また、以下は私のユーザー登録フォームです。
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :configure_permitted_parameters, if: :devise_controller?
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:zip, :email, :password, :password_confirmation) }
end
end
関連する User モデルは次のとおりです。
class User < ActiveRecord::Base
validates :zip, presence: true
geocoded_by :zip
after_validation :geocode
end
私の登録フォーム:
<h2>Sign up</h2>
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<div><%= f.label :email %>
<%= f.email_field :email, :autofocus => true %></div>
<div><%= f.label :zip %>
<%= f.text_field :zip %> </div>
<div><%= f.label :password %>
<%= f.password_field :password %></div>
<div><%= f.label :password_confirmation %>
<%= f.password_field :password_confirmation %></div>
<div><%= f.submit "Sign up" %></div>
<% end %>
<%= render "devise/shared/links" %>
このエラーが発生する理由について何か考えはありますか? サインアップ フォームに緯度と経度のフィールドを含める必要がありますか? 前もって感謝します!
編集
私の User テーブルのスキーマは次のとおりです。
class DeviseCreateUsers < ActiveRecord::Migration
def self.up
create_table(:users) do |t|
t.integer :zip
t.float :latitude
t.float :longitude
## Database authenticatable
t.string :email, :null => false, :default => ""
t.string :encrypted_password, :null => false, :default => ""
## Recoverable
t.string :reset_password_token
t.datetime :reset_password_sent_at
## Rememberable
t.datetime :remember_created_at
## Trackable
t.integer :sign_in_count, :default => 0
t.datetime :current_sign_in_at
t.datetime :last_sign_in_at
t.string :current_sign_in_ip
t.string :last_sign_in_ip
end
end
end