現在、以下のログインで有名なgemを使用しログインをする機能を実装し、email,uid以外にもユーザー名とプロフィール画像のカラムも追加し保存ができるようになりました。
しかし、プロフィールをtext型で入力するtextareaのフォームを追加すると、表示にエラーが起きてしまいます。
はうまく行くがprofileと言うテキストエリアを追加すると
エラー画面の表示となってしまいます。
エラーの原因として関連しそうなfileをいかに記します。
ruby
1views/devise/registrations/edit.html.erb 2 <div class="field"> 3 <%= f.label :profile %><br /> 4 <%= f.text_area :profile,:placeholder => 'エンジニア経験3年です。趣味は旅行。Rubyをメインに初心者にもわかりやすく教えていきます!まずは気軽にご連絡ください^^',rows="3", class: 'form-control login_mail_form font-awesome' %> 5 </div>
ruby
1models/user.rb 2class User < ApplicationRecord 3 4 devise :database_authenticatable, :registerable, 5 :recoverable, :rememberable, :trackable, :validatable, 6 :lockable, :timeoutable, :omniauthable, 7 omniauth_providers: [:twitter] 8 9 10 def self.from_omniauth(auth) 11 find_or_create_by(provider: auth["provider"], uid: auth["uid"]) do |user| 12 user.provider = auth["provider"] 13 user.uid = auth["uid"] 14 user.username = auth["info"]["nickname"] 15 user.profimage = auth["info"]["image"] 16 user.profile = auth["info"]["description"] 17 end 18 end 19 20 def self.new_with_session(params, session) 21 if session["devise.user_attributes"] 22 new(session["devise.user_attributes"]) do |user| 23 user.attributes = params 24 end 25 else 26 super 27 end 28 end 29end
ruby
1migrate/2017******_add_profdetails_to_users.rb 2class AddProfdetailsToUsers < ActiveRecord::Migration[5.1] 3 def change 4 add_column :users, :profimage, :string 5 add_column :users, :profile, :text 6 add_column :users, :portfolio, :string 7 end 8end
ruby
1application_controller.rb 2class ApplicationController < ActionController::Base 3 protect_from_forgery with: :exception 4 before_action :configure_permitted_parameters, if: :devise_controller? 5 6 7 def after_sign_in_path_for(resource) 8 edit_user_registration_path 9 end 10 11 12 private 13 def sign_in_required 14 redirect_to new_user_session_url unless user_signed_in? 15 end 16 17 18 protected 19 def configure_permitted_parameters 20 devise_parameter_sanitizer.permit(:sign_up, keys: [:username, :profimage, :profile]) 21 devise_parameter_sanitizer.permit(:account_update, keys: [:username,:profimage, :profile]) 22 end 23end 24
そのほか、この問題の解決に必要と思われる情報を教えていただければ追記していきますので、この問題について分かる方、心当たりある方ぜひお気軽にでもご質問、ご回答頂けますと幸いです。
よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。