0

我正在使用 databasedotcom 和 databasedotcom-rails gem,以便从表单提交中生成进入 Salesforce 的潜在客户。它是独立工作的,直到我将控制器嵌套在父级下,现在当我按下提交时,我收到此路由错误:

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

这是我的所有代码:

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 %>
4

1 回答 1

0

问题在于你的形式。使用您编写的路线,这些路线将new_event_lead_path映射到您的LeadsController#new操作的 GET 请求。在命令行上运行rake routes以确认这一点。

您要将表单提交到LeadsController#create. Lead当您在表达式中使用新实例时,Rails 会为您设置这个,simple_form_for [@event, @lead]前提是您不覆盖 url。因此,更新您的表单:

<%= simple_form_for [@event, @lead] do |f| %>
于 2013-05-09T03:27:59.483 回答