Reusing form_for to view mail program errors while faking

I have form_for in the new.html.erb template, where I do the usual save to the database, and then email when it succeeds. I want the mailer to send the same new.html.erb as the body and submit the model so that the form is completely filled. I get the following error:

undefined method `protect_against_forgery?' for #<#<Class:0x000000049d7110>:0x000000049d4690>

In the line immediately after the form_for tag (since I think it inserts the auth token token). Is there any way around this so that I can reuse the template in my inbox?

This is what the mailer code looks like

class MaintenanceMailer < ActionMailer::Base
  helper :application  

  def request_email(maintenance)
    mail :to => maintenance.community.email, :subject => "Maintenance" do |format|
      format.html { render :layout => 'default', :template => 'maintenance/new' }
    end    
  end
end  
+3
source share
4 answers

, :

    def protect_against_forgery?
      false
    end

, - verify_authenticity_token, .

+6

Sam C, . .

ApplicationHelper.send(:define_method, :protect_against_forgery?) { false }
html = render_to_string(template: "quotations/show", layout: "application_print")

_against_forgery? .

+4

, . form_for ? , , div form_for, .

0

form_for template.new.html,

you can check this for How to remove token_authentication from rail forms

0
source

Source: https://habr.com/ru/post/1757172/


All Articles