rails入門書を見ながらメッセージボードを作っています。
「NoMethod 」エラーが出てしまいました。
エラー内容
NoMethodError in BoardMessagesController#index undefined method `authenticate_account!' for #<BoardMessagesController:0x00007ff175d69ef8> Did you mean? authenticate_with_http_basic Extracted source (around line #428): 426 427 428 429 430 431 lambda do |target, value, &block| target, block, method, *arguments = expand(target, value, block) target.send(method, *arguments, &block) end end
メソッドが定義されていないというのはわかりました。
しかし、具体的にどうコードを書きなおせば良いのかわかりません。
コントローラー内容
class BoardMessagesController < ApplicationController before_action :set_board_message, only: [:show, :edit, :update, :destroy] before_action :authenticate_account! layout 'board_message' # GET /board_messages # GET /board_messages.json def index @board_messages = BoardMessage.page(params[:page]).order('created_at desc') users = BoardUser.where('account_id == ?', current_account.id)[0] if users == nil then user = BoardUser.new user.account_id = current_accunt.id user.nickname = '<<no name>>' user.save users = BoardUser.where 'account_id == ?', current_account.id end @board_user = users @board_message = BoardMessage.new @board_message.board_user_id = @board_user_id end # GET /board_messages/1 # GET /board_messages/1.json def show redirect_to '/board_messages' end # GET /board_messages/new def new redirect_to '/board_messages' end # GET /board_messages/1/edit def edit redirect_to '/board_messages' end # POST /board_messages # POST /board_messages.json def create @board_message = BoardMessage.page(params[:page]).order('created_at desc') @board_message = BoardMessage.new(board_message_params) @board_user = BoardUser.where('account_id == ?', current_account.id)[0] respond_to do |format| if @board_message.save format.html { redirect_to '/board_messages' } format.json { render :show, status: :created, location: @board_message } else format.html { render :index } format.json { render json: @board_message.errors, status: :unprocessable_entity } end end end # PATCH/PUT /board_messages/1 # PATCH/PUT /board_messages/1.json def update redirect_to '/board_messages' end # DELETE /board_messages/1 # DELETE /board_messages/1.json def destroy redirect_to '/board_messages' end private # Use callbacks to share common setup or constraints between actions. def set_board_message @board_message = BoardMessage.find(params[:id]) end # Only allow a list of trusted parameters through. def board_message_params params.require(:board_message).permit(:content, :board_user_id) end end
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。