简体   繁体   English

提交表单databasedotcom-gem时在嵌套控制器上路由错误

[英]Routes error on nested controller when submitting form, databasedotcom-gem

I am using the databasedotcom & databasedotcom-rails gem so that I get generate leads into Salesforce from form submissions. 我正在使用databasedotcom&databasedotcom-rails gem,以便从表单提交中获取潜在客户到Salesforce。 It was working standalone until I nested the controller under a parent, and now when I press submit I get this routes error: 在将控制器嵌套在父级下之前,它一直是独立工作的,现在当我按Submit时,出现以下路由错误:

No route matches [POST] "/events/516ee9a0421aa9c44e000001/leads/new"

Here is all my code: 这是我所有的代码:

resources :events do
  resources :leads
end

class LeadsController < ApplicationController
   include Databasedotcom::Rails::Controller

  def new
    @lead = Lead.new
    respond_to do |format|
    format.html # new.html.erb
    format.json { render :json => @lead }
    end
 end

 def create
   @lead = Lead.new(params[:lead])
   @lead.event_id = params[:event_id]
   @lead['OwnerId'] = '005b0000000WxqE'   
   @lead['IsConverted'] = false
   @lead['IsUnreadByOwner'] = false
   respond_to do |format|
   if @event_lead.save
    format.html { redirect_to @lead, :notice => 'Lead was successfully created.' }
    format.json { render :json => @lead, :status => :created, :location => @lead }
  else
    format.html { render :action => "new" }
    format.json { render :json => @lead.errors, :status => :unprocessable_entity }
  end
  end
  end
end   

<%= simple_form_for [@event, @lead], url: new_event_lead_path do |f| %>
  <%= f.input :Download_Brochure__c, :check => "true",  :as => :boolean, :as => :hidden %>
  <%= f.input :FirstName %>
  <%= f.input :LastName %>
  <%= f.input :Company %>
  <p>Also interested in:</p>
  <%= f.input :Sponsor_Request__c, :as => :boolean, :label => "Sponsoring" %>
  <%= f.input :Presenting__c, :as => :boolean, :label => "Presenting" %>
  <%= f.input :Newsletter_Signup__c, :as => :boolean, :label => "Newletter" %>
  <%= f.input :Privacy_Policy__c, :as => :boolean, :checked => true, :label => "Would you like to stay updated" %>
  <%= f.button :submit, :label => "Submit" %>
<% end %>

The problem is in your form. 问题出在您的表格上。 With the routes as you have written them, the new_event_lead_path maps to a GET request to your LeadsController#new action. 使用您编写的路线, new_event_lead_path映射到对LeadsController#new操作的GET请求。 Run rake routes on the command line to confirm this. 在命令行上运行rake routes以确认这一点。

You want to submit the form to LeadsController#create . 您要将表单提交给LeadsController#create Rails will set this up for you when you use a new instance of Lead in the expression simple_form_for [@event, @lead] provided you don't override the url. 当您在表达式simple_form_for [@event, @lead]使用Lead的新实例时simple_form_for [@event, @lead]如果您不覆盖url simple_form_for [@event, @lead] Rails会为您进行设置。 Therefore, update your form: 因此,更新您的表单:

<%= simple_form_for [@event, @lead] do |f| %>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM