0

我在我的 Rails 控制器中设置了三个 cookie,用于获取访问者登陆网站时的一些信息。当他们提交表单时,我需要将这三个 cookie 的值与其他表单数据一起保存在数据库表中。我已经运行迁移以添加额外的列,但我没有找到任何有助于实际保存表单提交值的东西。

有谁知道这是否可行,如果可以,我该怎么做?

def process_contact_us
@form = Form.find(1)    
@contact_submission = ContactSubmission.new(params[:contact_submission])    
if @contact_submission.save
  if @contact_submission.newsletter
    begin
      logger.info "Sending autoresponder"
      et = ExactTarget.new(ApplicationController::ET_USER,ApplicationController::ET_PASS, true)
      et.add_subscriber_with_options({
        "Email__Address" => @contact_submission.email,
        "First__Name" => @contact_submission.first_name,
        "Last__Name" => @contact_submission.last_name,
        "Address" => @contact_submission.address,
        "Address__2" => @contact_submission.address2,
        "City" => @contact_submission.city,
        "State" => @contact_submission.state,
        "Zip__Code" => @contact_submission.zip,
        "TravelNewsletter" => "Yes"
      }, ApplicationController::ET_LIST_ID)
      et.single_send(@contact_submission.email, ApplicationController::ET_EMAIL_ID, "", "")             
      logger.info "Added to ET"
    rescue
    end
  end

  Notifier.deliver_contact_us(@contact_submission, @form)

  session[:form] = nil
  redirect_to "/contact-us/thank-you"
else
  flash[:form] = @contact_submission
  flash[:notice] = @form.error_message.blank? ? "First Name, Last Name, and Email are all required fields." : @form.error_message
  redirect_to :back
end

结尾

4

1 回答 1

1

要将信息保存到 contact_submission 对象,您应该在使用表单中的值初始化它们之后但在保存之前设置它的值:

@contact_submission = ContactSubmission.new(params[:contact_submission])
@contact_submission.super_cool_value = cookies[:super_cool_value]
if @contact_submission.save
  #.. continue on
于 2013-05-09T18:03:55.680 回答