我正在使用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 %>
答案 0 :(得分:0)
问题在于你的形式。通过您编写的路线,new_event_lead_path
会映射到您的LeadsController#new
操作的GET请求。在命令行上运行rake routes
以确认这一点。
您想将表单提交至LeadsController#create
。如果您不覆盖网址,则在表达式Lead
中使用simple_form_for [@event, @lead]
的新实例时,Rails会为您设置此项。因此,请更新您的表单:
<%= simple_form_for [@event, @lead] do |f| %>