ビューファイル
.header .title-header 支出入力 .spending-inner = form_for @spending do |f| .spending-inner_contents .spending-inner_contents__date %label.information{for: "date"} 日付 .spending__content__form--error = f.text_field :date, class: 'date', placeholder: '日付を選択', :type => "date", value: "" .spending-inner_contents__category = f.label 'カテゴリー', class: 'category_id' .spending__content__form--error = f.collection_select :category_id, @categories, :id, :category, {include_blank: "---"} ,class: "category_id" .spending-inner_contents__amount = f.label '金額', class: 'amount' .spending__content__form--error = f.text_field :amount, class: 'amount', placeholder: '金額を入力', :type => "amount" .completed-btn = f.submit "完了", class: "completed-btn", :type => "submit"
コントローラ
def new @spending = Spending.new @categories = Category.all end def create @spending = Spending.create(date: spending_params[:date], category_id: spending_params[:category_id], amount: spending_params[:amount], user_id: current_user.id) binding.pry end private def spending_params params.permit(:date, :category_id, :amount) end end
コントローラの@spendingをbinding.pryでみても、値がnilになっています。
ターミナル
[1] pry(#<SpendingsController>)> @spending => #<Spending:0x007fb3c8c1c1d0 id: 100, user_id: 7, date: nil, category_id: nil, amount: nil, created_at: Wed, 19 Jun 2019 05:56:03 UTC +00:00, updated_at: Wed, 19 Jun 2019 05:56:03 UTC +00:00>
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/06/19 06:17