テーブルから情報を持ってこれません
@item = Item.find(params[:id])で
エラーが出てしまいます
情報を持ってきたいのですがご教授願います
コントローラー
def pay @card = Card.find_by(user_id: current_user.id) @item = Item.find(params[:id]) @user = User.find(id= current_user.id) if @card.blank? redirect_to controller: "card", action: "new" else Payjp.api_key = ENV['PAYJP_PRIVATE_KEY'] Payjp::Charge.create( :amount => @item.price, :customer => @card.customer_id, :currency => 'jpy', ) redirect_to action: 'done' end
Haml
pay_purchase_index_pathに飛ぼうとするとエラーが出ます
= form_with url: pay_purchase_index_path, method: :post, local: true do |f| =f.submit "購入する",data: {"turbolinks" => false} ,class: "btn linkbtn"
コントローラー index
def index @item = Item.find(params[:format]) @card = Card.find_by(user_id: current_user.id) @user = User.find(id= current_user.id) if @card.blank? else
view
-# ページのヘッダー部分 %header.header = render 'shared/sub_header' -# メイン画面 %main.confirmation-main %section.confirmation-main__container -# メイン画面ヘッダー %h2.confirmation-main__container__header 購入内容の確認 -# 商品情報、値段 %section.confirmation-main__container__buy-content .confirmation-main__container__buy-content__inner %h3.confirmation-main__container__buy-content__inner__item =image_tag ("#{@item.image}"),class: "huku_1" .confirmation-main__container__buy-content__inner__item-name .confirmation-main__container__buy-content__inner__item-name__box = @item.product_name -# ポイント、支払い金額、購入ボタン .confirmation-main__container__buy-content__inner__buy-form .confirmation-main__container__buy-content__inner__buy-form__list %p.confirmation-main__container__buy-content__inner__buy-form__list__price ¥ = @item.price %span.confirmation-main__container__buy-content__inner__buy-form__list__price__text 送料込み %ul.confirmation-main__container__buy-content__inner__buy-form__list__point ポイントはありません .confirmation-buy-box %ul.confirmation-main__container__buy-content__inner__buy-form__list__table %li.confirmation-main__container__buy-content__inner__buy-form__list__table__list .confirmation-main__container__buy-content__inner__buy-form__list__table__list__left-text 支払い金額 .confirmation-main__container__buy-content__inner__buy-form__list__table__list__right-text ¥ = @item.price = form_with url: pay_purchase_index_path(@item.id), method: :post, local: true do |f| =f.submit "購入する",data: {"turbolinks" => false} ,class: "btn linkbtn" -# 配送先とユーザーの住所 %section.confirmation-main__container__buy-info .confirmation-main__container__buy-info__container %h3 配送先 %address.confirmation-main__container__buy-info__container__address .confirmation-main__container__buy-info__container__address__postal-code 〒 = @user.post_code .confirmation-main__container__buy-info__container__address__address-name = @user.address_prefecture = @user.address_city = @user.address_number .confirmation-main__container__buy-info__container__address__user-name = @user.address_last_name = @user.address_first_name =link_to "/purchase/show", class: 'confirmation-main__container__buy-info__container__user-info-fix',method: :get do %span 変更する > -# クレジットカード情報 %section.confirmation-main__container__credit-info .confirmation-main__container__credit-info__inner %h3 支払い方法 - if @default_card_information.blank? %br / - else .confirmation-main__container__credit-info__inner__card-number = "**** **** **** " + @default_card_information.last4 .confirmation-main__container__credit-info__inner__deadline - exp_month = @default_card_information.exp_month.to_s - exp_year = @default_card_information.exp_year.to_s.slice(2,3) = exp_month + " / " + exp_year = image_tag '//www-mercari-jp.akamaized.net/assets/img/card/visa.svg?210491352', class: "confirmation-main__container__credit-info__inner__logo" =link_to card_new_path, class: 'confirmation-main__container__buy-info__container__user-info-fix' do %span 変更する > -# merucariロゴフッター = render 'shared/sub_footer'
エラーメッセージ
Couldn't find Item without an ID Request info Request parameters {"controller"=>"purchase", "action"=>"done"} Rack session (Object too large. Modify ActionDispatch::Request::Session#inspect or adjust BetterErrors.maximum_variable_inspect_size if you need to see it.) Local Variables id nil Instance Variables @_action_has_layout true @_routes nil @_request (Object too large. Modify ActionDispatch::Request#inspect or adjust BetterErrors.maximum_variable_inspect_size if you need to see it.) @_response (Object too large. Modify ActionDispatch::Response#inspect or adjust BetterErrors.maximum_variable_inspect_size if you need to see it.) @_lookup_context #<ActionView::LookupContext:0x00007fd024bc8828 @details_key=nil, @cache=true, @prefixes=["purchase", "application"], @rendered_format=nil, @details={:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby, :coffee, :jbuilder, :haml]}, @view_paths=#<ActionView::PathSet:0x00007fd024bc8738 @paths=[#<ActionView::OptimizedFileSystemResolver:0x00007fd0208c11b0 @pattern=":prefix/:action{.:locale,}{.:formats,}{+:variants,}{.:handlers,}", @cache=#<ActionView::Resolver::Cache:0x7fd0208c1188 keys=24 queries=0>, @path="/Users/katoukento/projects/freemarket_sample_62b/app/views">, #<ActionView::OptimizedFileSystemResolver:0x00007fd0208c19a8 @pattern=":prefix/:action{.:locale,}{.:formats,}{+:variants,}{.:handlers,}", @cache=#<ActionView::Resolver::Cache:0x7fd0208c1980 keys=16 queries=0>, @path="/Users/katoukento/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/devise-4.7.1/app/views">, #<ActionView::OptimizedFileSystemResolver:0x00007fd0208c20d8 @pattern=":prefix/:action{.:locale,}{.:formats,}{+:variants,}{.:handlers,}", @cache=#<ActionView::Resolver::Cache:0x7fd0208c20b0 keys=16 queries=0>, @path="/Users/katoukento/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/kaminari-core-1.1.1/app/views">]>> @_action_name "done" @_response_body nil @marked_for_same_origin_verification true @_config {} @current_user #<User id: 4, email: "katou@gmail.com", created_at: "2019-11-29 02:37:47", updated_at: "2019-11-29 02:37:47", provider: nil, uid: nil, nickname: "加藤", last_name: "けんと", first_name: "加藤", last_name_kana: "ケント", first_name_kana: "カトウ", birthday_year: 1, birthday_month: 2, birthday_day: 2, phone_number: 333, address_last_name: "加藤", address_first_name: "けんと", address_last_name_kana: "カトウ", address_first_name_kana: "ケント", post_code: "6893541", address_prefecture: "31", address_city: "米子市", address_number: "0-0-0", address_building: "1", address_phone_number: nil, introduce: nil> @card #<Card id: 19, user_id: 4, customer_id: "cus_d2f3014728cb6d51a81df8f63c45", card_id: "car_39b06cf04c45f84f8ce838193b23", created_at: "2019-11-29 03:20:08", updated_at: "2019-11-29 03:20:08"> @_params <ActionController::Parameters {"controller"=>"purchase", "action"=>"done"} permitted: false>
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。