###実現したいこと
グループチャットでグループの編集機能を実装しようとしているが、
以下のエラーにより、実装ができない
###エラー内容
NoMethodError in GroupsController#update
undefined method `update' for nil:NilClass
###ソースコード
route.rb
Rails.application.routes.draw do devise_for :users root to: "groups#index" resources :users, only: [:edit, :update] resources :groups, only: [:index,:new, :create, :edit, :update] do resources :messages,only: [:index, :create] end end
group.controller.rb
def index end def new @group = Group.new @group.users << current_user end def create @group = Group.new(group_params) if @group.save redirect_to root_path, notice: 'グループを作成しました' else render :new end end def edit @group = Group.find(params[:id]) end def update @gruops = Group.find(params[:id]) if @group.update(group_params) redirect_to group_messages_path(group), notice: 'グループを更新しました' else render :edit end end private def group_params params.require(:group).permit(:name, user_ids: []) end end
form.html.hanl(グループを編集)
= form_for group do |f| - if group.errors.any? .chat-group-form__errors %h2= "#{group.errors.full_messages.count}件のエラーが発生しました。" %ul - group.errors.full_messages.each do |message| %li= message .chat-group-form__field .chat-group-form__field--left = f.label :name, class: 'chat-group-form__label' .chat-group-form__field--right = f.text_field :name, class: 'chat__group_name chat-group-form__input', placeholder: 'グループ名を入力してください' .chat-group-form__field.clearfix .chat-group-form__field.clearfix .chat-group-form__field--left %label.chat-group-form__label{:for => "chat_group_チャットメンバー"} チャットメンバー .chat-group-form__field--right = f.collection_check_boxes :user_ids, User.all, :id, :name .chat-group-form__field.clearfix .chat-group-form__field--left .chat-group-form__field--right = f.submit class: 'chat-group-form__action-btn'
よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/01/24 13:36