【问题标题】:Change the edit action with devise with custom controller?使用自定义控制器更改编辑操作?
【发布时间】:2020-12-17 13:23:52
【问题描述】:

我正在使用带有自定义控制器的设计(用户控制器,而不是设计控制器)

我需要更改 create 操作,它工作正常。它看起来像这样:

  def create
   super do |user|
      @patient = user.build_patient
      @patient.save
   end
  end

但是当我尝试使用 edit 操作的相同技术时,实例变量在视图中使用时似乎是 nil(当我使用 byebug/@ 时,它似乎在控制器中设置得很好987654326@手动测试)

def edit
# binding.pry
  super do |user|
    if current_user.physician.stripe_details_submitted
      Stripe.api_key = Rails.application.credentials[Rails.env.to_sym][:stripe][:secret_stripe_test_key]
      @stripe_account_dashboard_link = Stripe::Account.create_login_link(current_user.physician.stripe_account).url
    end
  end
end

有什么想法吗?

【问题讨论】:

    标签: ruby-on-rails devise


    【解决方案1】:

    我在写完这个问题后就明白了为什么。这是以防其他人需要它。

    更改创建方法时使用super,如下所示:

      def create
       super do |user|
         ...
       end
      end
    
    

    super 的使用不是edit 操作所必需的(所以只需删除super):

    def edit
    
        if current_user.physician.stripe_details_submitted
          Stripe.api_key = Rails.application.credentials[Rails.env.to_sym][:stripe][:secret_stripe_test_key]
          @stripe_account_dashboard_link = Stripe::Account.create_login_link(current_user.physician.stripe_account).url
        end
    
    end
    

    这行得通!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-19
      • 1970-01-01
      • 2022-01-08
      • 1970-01-01
      • 1970-01-01
      • 2015-02-14
      • 1970-01-01
      • 2011-12-03
      相关资源
      最近更新 更多