Ruby on rails Rails交互者:我怎么能有flash消息?

Ruby on rails Rails交互者:我怎么能有flash消息?,ruby-on-rails,ruby-on-rails-4,flash-message,Ruby On Rails,Ruby On Rails 4,Flash Message,我正在努力解决Interactor gem中的一个小功能(来自我们在Collective idea的朋友) 我想做的是在我的交互器中有一个flash消息,就像我在控制器中一样 这是我在控制器中的create方法,我在其中实例化了我的interactior: def create buy_credits = BuyCredit.new(send_transactions_params) buy_credits.perform redirect_to profile_pat

我正在努力解决Interactor gem中的一个小功能(来自我们在Collective idea的朋友)

我想做的是在我的交互器中有一个flash消息,就像我在控制器中一样

这是我在控制器中的create方法,我在其中实例化了我的interactior:

def create
    buy_credits = BuyCredit.new(send_transactions_params)
    buy_credits.perform

    redirect_to profile_path
end
def build_transaction

    if context[:transaction][:recipient_id].nil? && context[:transaction][:recipient_type].nil?

      @transaction = user.transactions.build(context[:transaction])
      # flash[:success] = I18n.t('.bought_credits_for_client', recipient: user)

    elsif context[:transaction][:recipient_id].present? && context[:transaction][:recipient_type] == Organisation.name

      current_organisation = user.organisations.find(context[:transaction][:recipient_id])
      @transaction = current_organisation.transactions.build(context[:transaction])
      # flash[:success] = I18n.t('.bought_credits_for_organisation', recipient: current_organisation)

    else
      # flash[:error] = I18n.t('.cant_buy_credits')
    end

  end
下面是我的互动器的构建:

def create
    buy_credits = BuyCredit.new(send_transactions_params)
    buy_credits.perform

    redirect_to profile_path
end
def build_transaction

    if context[:transaction][:recipient_id].nil? && context[:transaction][:recipient_type].nil?

      @transaction = user.transactions.build(context[:transaction])
      # flash[:success] = I18n.t('.bought_credits_for_client', recipient: user)

    elsif context[:transaction][:recipient_id].present? && context[:transaction][:recipient_type] == Organisation.name

      current_organisation = user.organisations.find(context[:transaction][:recipient_id])
      @transaction = current_organisation.transactions.build(context[:transaction])
      # flash[:success] = I18n.t('.bought_credits_for_organisation', recipient: current_organisation)

    else
      # flash[:error] = I18n.t('.cant_buy_credits')
    end

  end
你可以看到我想要的flash消息类型,它们是注释行

当然,我可以吃点像这样的东西

if interactor.success?
    redirect_to profile_path
else
在我的控制器中,但正如您在我的评论行中所看到的,我有两种“类型”的成功


谢谢

多亏了另一位同事的帮助,我们成功地解决了这个问题:我们只需将flash对象(在控制器中实例化)传递给上下文,由交互者接收。因此,交互者将其消息添加到对象中,该对象随后在控制器中可用

以下是我的上下文结构:

def send_transactions_params
    params_to_send = {
        transaction: transaction_params,
        buyer: current_user,
        flash: flash
    }
    params_to_send
end