下記のコードで <h1>プロフィールを編集</h1>
は表示されるのですが、 form_for
内のlabel
もtext_field
も表示されません。
controllerの@profile = current_user
で何も渡せていないからでしょうか?
これらのコードでしたいことは、user.rbとprofile.rbを1対1で繋ぎ、プロフィール画面を作ることです。
よろしくお願いします!
↓edit.html.erb
<div class="text-center"> <h1>プロフィールを編集</h1> </div> <div class="row"> <div class="col-md-6 col-md-offset-3"> <% form_for (@profile),:url => {:action => :update} do |f| %> <%= render 'layouts/error_messages', model: f.object %> <div class="field form-group"> <%= f.label :name, '名前' %><br /> <%= f.text_field :name, autofocus: true, autocomplete: "name", :placeholder => "村人 太郎", class: 'form-control' %> </div> <div class="field form-group"> <%= f.label :comment, '説明' %><br /> <%= f.text_area :comment, autofocus: true, autocomplete: "comment", :size => "20x7", :placeholder => "ご自由にお書き下さい", class: 'form-control' %> </div> <div class="actions"> <%= f.submit "更新する", class: "btn btn-outline-primary" %> </div> <% end %> <%= link_to "戻る", :back %> </div> </div>
↓profile_controller.rb
class ProfilesController < ApplicationController def edit @profile = current_user end def update @profile = current_user if @user.update(profile_params) flash[:success] = '更新しました' redirect_to @user else flash.now[:danger] = '更新できませんでした' render :edit end end private def profile_params params.require(:@user).permit(:comment) end end
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/06/15 11:28