rails初心者です。
pay.jpで課金機能を作ったものの、購入後に@teacher.nameと@teacher.emailが表示されるようにしたいですのですが、うまく表示されません。
teacher_controllerの@teacher.nameと@teacher.emailとproducts_controllerでも使えるようにできていないからと推測はしているものの、エラーは出ていないので、どこに不備があるかわからない状態です。
routes.rb
#Pay.jpの機能 resources :teachers do resources :products do collection do post 'purchase' end end end
products_controller
class ProductsController < ApplicationController def index @teacher = Teacher.find_by(id: params[:id]) @teacher = Teacher.new(teacher_params) end def purchase @teacher = Teacher.find_by(id: params[:id]) @teacher = Teacher.new(teacher_params) Payjp.api_key = ENV["PAYJP_SECRET_KEY"] Payjp::Charge.create( :amount => 9800, :card => params['payjp-token'], :currency => 'jpy' ) end private def teacher_params params.permit(:name, :email) end end
teachers/show.html.erb
<%= link_to "この先生に相談する",teacher_products_path(@teacher),class:"waves-effect waves-light btn"%>
products/index.html.erb
<div class="payjp-purchase"> <p>この先生に連絡するには利用料が必要となります。</p> <%= form_tag(action: :purchase, method: :post) do %> <script type="text/javascript" src="https://checkout.pay.jp" class="payjp-button" data-key="<%= ENV["PAYJP_PUBLIC_KEY"] %>"></script> <% end %> <%= link_to "戻る", teachers_index_path %> </div>
products/purchase.html.erb
<div class="thanks"> <h6>支払いが完了しました。</h6> <div class="teacher-info"> <p><%= @teacher.name%>先生 <%= @teacher.email%></p>#これが表示されない </div> </div>
お力貸していただける方がいらっしゃれば、ご教授していただけると光栄です。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。