我正在为 Interactor gem 中的一个小功能而苦苦挣扎(来自我们在 Collective idea 的朋友)。
我想要做的是在我的交互器中显示一条消息,就像在我的控制器中一样。
这是我的控制器中的 create 方法,我在其中实例化了我的交互器:
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
在我的控制器中,但正如您在我的评论中看到的那样,我有两种“类型”的成功......
谢谢!