エラー
ActionController::UnknownFormat in xxController#xx

テンプレートがない。
今回はviews/orders下にindex.html.hamlがなかったのが原因。
該当する場所に適切な名前のビューを作れば解決。
Syntax unexpected keyword_ensure, expecting end-of-input

railsの埋め込みに文法ミスあり。
フォームや繰り返し処理など、複数行にわたるもの。
原因:
form_for
のdo |f|
忘れ。
ActiveRecord::StatementInvalid in Devise::RegistrationsController#create
"Field 'name' doesn't have a default value"とな。
アカウント新規登録画面で「アカウント作成」をクリックしたらエラー。URLは'/users'。
このURLは間違いだからここのリダイレクトは直さなあかんけど、それ以前のエラー(DB絡み)な気がする。
キター!!これだ原因。
原因:
deviseでは初期状態でサインアップ時にメールアドレスとパスワードのみを受け取るようにストロングパラメーターが設定してあるので、追加したキーのパラメーターは許可されていません。追加のパラメーターを許可したい場合は、application_controller
においてbefore_action
にconfigure_permitted_parameters
メソッドを設定します
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
before_action :configure_permitted_parameters, if: :devise_controller?
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up, keys: [:nickname])
end
end
ActionController::InvalidAuthenticityToken
なにこれ、初めて見た…
Rails4のCSRF対策で「Can't verify CSRF token authenticity」エラーが参考になります。
Railsは外部からのリクエストをはじくようにできてるらしい。
解決策
class ProductsController < ApplicationController
protect_from_forgery except: :search # searchアクションを除外
def index
end
def search
@products = Product.where('name LIKE(?)', "%#{params[:keyword]}%")
redirect_to 'index'
end
end
undefined method `pry'
解決策
- gem 'pry-rails' をインストール
- サーバー再起動(忘れずに!)
First argument in form cannot contain nil or be empty
原因
order_detailオブジェクトが生成されていないから、"nil"は引数に取れないよ〜って言われてる。
解決策
この画面を呼ぶアクションで、事前に@order_detail = OrderDetail.new
など、空のオブジェクトを生成しておく。