【问题标题】:How to use form_for in ActionMailer如何在 ActionMailer 中使用 form_for
【发布时间】:2013-06-25 06:34:23
【问题描述】:

我想向用户发送一封包含表单的电子邮件:

我尝试了以下

booking_confirmation.html.erb:

<%= form_for(@event, :html => { :method => :put }) do |f| %>
<%= f.hidden_field(:customer_id, :value => nil) %>
<%= f.submit "Cancel", class: "btn btn-large btn-primary", :confirm => 'Are you sure?' %>
<% end %>

但是我必须在 UserMailerHelper 中将 protect_against_forgery 设置为 false,这会奇怪地破坏我的登录操作...

有没有更简单的方法可以向我的event_url 发送一个带有一个参数:customer_id 的PUT 请求?

感谢您的帮助!

我也尝试了以下方法。它不起作用,有没有人知道为什么并可以帮助我通过它?

<%= link_to "Cancel", url_for(controller: 'events', action: 'update', only_path: false, :customer_id => "0"), :confirm => 'Are you sure?' %>

【问题讨论】:

    标签: ruby-on-rails actionmailer form-for


    【解决方案1】:

    你为什么用form_for的形式,换成带参数的链接形式。

        <%= link_to "Cancel", url_for(:action => event_url, :customer_id => @event.customer_id), :class => "btn btn-large btn-primary", :confirm => 'Are you sure?' %>
    

    【讨论】:

    • 感谢您的回复!我试过了,但后来收到以下错误:No route matches {:action=&gt;"show", :controller=&gt;"events"}。我认为有必要指定操作,但我不知道如何
    • 你的 route.rb 配置是什么?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-03-09
    • 1970-01-01
    • 2014-02-11
    • 2011-12-05
    • 1970-01-01
    • 2022-09-23
    • 1970-01-01
    相关资源
    最近更新 更多