解決したいこと
gem deviseを使用してユーザー情報登録機能を作成しています。
html.hamlの中でf.text_field :addressを記述していますが、
入力後データを保存しようとすると以下のエラーが出ます。
エラーメッセージ
NoMethodError in Users::RegistrationsController#create_address
undefined method `permit' for "[入力した内容]":String
user/registrations_controller.rb
def new
@user = User.new
end
def create
@user = User.new(sign_up_params)
if @user.valid?
session["devise.regist_data"] = {user: @user.attributes}
session["devise.regist_data"][:user]["password"] = params[:user][:password]
redirect_to addresses_path
else
render :new
end
end
def create_address
@user = User.new(session["devise.regist_data"]["user"])
@address = Address.new(address_params)
if @address.valid?
@user.save
@address = Address.new(address_params.merge(user_id: @user.id))
@address.save
session["devise.regist_data"]["user"].clear
sign_in(:user, @user)
else
render :new_address
end
end
protected
def address_params
params.require(:address).permit(:post_number, :prefecture, :city, :address, :apartment)
end
routes.rb
devise_for :users, controllers: {
registrations: 'users/registrations',
}
devise_scope :user do
get 'addresses', to: 'users/registrations#new_address'
post 'addresses', to: 'users/registrations#create_address'
end
db/migrate/addresses.rb
t.string :address , null: false
rails routes
user_registration PATCH /users(.:format) users/registrations#update
PUT /users(.:format) users/registrations#update
DELETE /users(.:format) users/registrations#destroy
POST /users(.:format) users/registrations#create
addresses GET /addresses(.:format) users/registrations#new_address
POST /addresses(.:format) users/registrations#create_address
root GET / items#index
user GET /users/:id(.:format) users#show