Ruby on rails Rails-由于参数原因表单未在外部API中过帐
这是我处理表格的模型Ruby on rails Rails-由于参数原因表单未在外部API中过帐,ruby-on-rails,ruby,ruby-on-rails-3,forms,Ruby On Rails,Ruby,Ruby On Rails 3,Forms,这是我处理表格的模型 class Form include ActiveModel::Validations include ActiveModel::Conversion include ActiveModel::Translation extend ActiveModel::Naming attr_accessor :config, :client, :subject, :email, :custom_field, :phone_number_28445, :comp
class Form
include ActiveModel::Validations
include ActiveModel::Conversion
include ActiveModel::Translation
extend ActiveModel::Naming
attr_accessor :config, :client, :subject, :email, :custom_field, :phone_number_28445, :company_28445, :description
validates_presence_of :subject, :message => '^Please enter your name'
validates_presence_of :description, :message => '^Question(s), and/or feedback can not be blank'
validates :email, presence: true
validates_format_of :email, :with => /^[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]{2,4}$/i
def initialize(attributes = {})
attributes.each do |name, value|
send("#{name}=", value)
end
self.config = YAML.load_file("#{Rails.root}/config/fresh_desk.yml")[Rails.env]
self.client = Freshdesk.new(config[:url], config[:api_key], config[:password])
end
def post_tickets
client.post_tickets({
:subject => "Web Inquiry From, #{subject}",
:email => email,
:custom_field => {:phone_number_28445 => phone_number_28445},
:description => description
})
end
def persisted?
false
end
end
在我的post_tickets方法中,它运行良好……问题在于
:custom_field_phone_number_28445 => custom_field_phone_number_28445
我知道这一点,因为当我把它从表格中拿出来的时候……当我把它加回去的时候,我会得到一个
Completed 500 Internal Server Error in 1222ms
Freshdesk::ConnectionError (Connection to the server failed. Please check hostname):
lib/freshdesk.rb:77:in `rescue in block in fd_define_post'
lib/freshdesk.rb:70:in `block in fd_define_post'
app/models/form.rb:25:in `post_tickets'
app/controllers/website/contacts_controller.rb:8:in `create'
config/initializers/quiet_assets.rb:8:in `call_with_quiet_assets'
下面是它工作时发布的内容
Parameters:
{"utf8"=>"✓", "authenticity_token"=>"g91E0jYezX+5gFAe6R/hUPs9b+UqS1uMqki4rE6xU28=",
"contacts"=>{"subject"=>"ricky ahn ",
"email"=>"ricky@onehouse.net",
"custom_field"=>{"phone_number_28445"=>"123-123-1234"},
"description"=>"test"},
"commit"=>"Submit"}
Redirected to http://localhost:3000/contacts/new
Completed 302 Found in 2142ms (ActiveRecord: 0.0ms)
下面是当它工作时发布的内容
Parameters: {"utf8"=>"✓", "authenticity_token"=>"g91E0jYezX+5gFAe6R/hUPs9b+UqS1uMqki4rE6xU28=",
"contacts"=>{"subject"=>"ricky ahn ",
"email"=>"ricky@onehouse.net",
"custom_field"=>{"phone_number_28445"=>"123-123-1234"},
"description"=>"test"}, "commit"=>"Submit"}
Completed 500 Internal Server Error in 841ms
我不知道我现在做错了什么
这是html/haml
= form_for(:contacts, url: contacts_path) do |f|
= f.error_messages
= f.label :subject, "Name"
%span{style: 'color: red'} *
= f.text_field :subject, class: "text_field width_100_percent"
%br
%br
= f.label "Email"
%span{style: 'color: red'} *
%br
= f.email_field :email, class: "text_field width_100_percent"
%br
%br
= f.label "Phone"
%br
= f.fields_for :custom_field do |custom_field|
= custom_field.text_field :phone_number_28445, class: "text_field width_100_percent"
%br
%br
= f.label "Question(s), and/or feedback"
%span{style: 'color: red'} *
%br
= f.text_area :description, class: "text_field width_100_percent", style: 'height: 100px;'
%br
%br
= f.submit "Submit", class: 'btn btn-warning'
您指定此名称是否有原因?导致问题的值是唯一一个具有重写表单名称的值
= f.text_field :custom_field_phone_number_28445,
name: 'contacts[custom_field][phone_number_28445]',
class: "text_field width_100_percent"
难道不应该是:
= f.text_field :custom_field_phone_number_28445,
class: "text_field width_100_percent"
所有其他属性都不会嵌套到表单上的子名称中。。。我猜表单模型中没有设置值,结果是零,链条下面的一些东西对此很生气。是的,我必须在它上面指定一个名称,因为它必须这样传入…否则它不会发布…所以我认为这与此有关,但我不知道如何在我的模型中的方法中这样发布当我不指定名称时,参数如下所示“custom_field_phone_number_28445”=>“123-123-1234”引发错误它应该看起来像这样的“custom_field”=>{“phone_number_28445”=>“123-123-1234”},但您随表单提交的内容并不是您向服务发布的内容。您提交的是rails应用程序,格式需要与
表单
对象匹配。一旦表单对象正确包含信息,您就可以继续计算post_tickets
API调用。是的,这就是我试图做的…ca我不知道它想要什么好吧,那很好。:)听起来你现在可能有一个新的FreshDesk客户问题…我从来没有用过它…祝你好运!