LoginSignup
0
0

More than 1 year has passed since last update.

変数が代入できない

Posted at

結論

createアクションをendで終わらせる前に次のshowアクションを書いてしまった。
実際は以下。
createアクションのendを描く前にshowとdestroyのアクションを書いてしまい、
うまくshowアクションとdestroyアクションが機能しなかった

class CardsController < ApplicationController
before_action :authenticate_user!
def new
redirect_to root_path if user_signed_in? && current_user.card
end

def new
@card = Card.new
end

def create
Payjp.api_key = ENV["PAYJP_SECRET_KEY"]
card = Card.find_by(user_id: current_user.id)
customer = Payjp::Customer.retrieve(card.customer_token)
@card = customer.cards.first

if @card.save
  redirect_to root_path
else
  render "new"
end


def show
  Payjp.api_key = ENV["PAYJP_SECRET_KEY"]
  card = Card.find_by(user_id: current_user.id)
  customer = Payjp::Customer.retrieve(card.customer_token)
  @card = customer.cards.first
end

def destroy
  card = Card.find_by(user_id: current_user.id)
  Payjp.api_key = ENV["PAYJP_SECRET_KEY"]
  customer = Payjp::Customer.retrieve(card.customer_token)
  customer.delete
  card.delete
    redirect_to action: "new"
end

end
end

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0